I have to create a program that will calculate addition, subtraction, multiplication, and division of fractions.(adsbygoogle = window.adsbygoogle || []).push({});

I have that part done.

But one other requirement is that I need to have it looped so that the user could continue as long as he likes.

I also need a way to output the number of correct answers out of the number of attempts. in this form:

I have no idea how to do this. The only thing remotely similar in my knowledge is calculating average of values. Any tips or help would be appreciated. You answered 6 out of 8 questions correctly.

You have an overall percentage of 75.0%. Good bye.

For the loop, i attempted to use a do while statement like so:

however, i'm not sure if i did it right, or where exactly to place it. whenever i tried placing it somewhere, i twould give me 2-3 errors.Code (Text):do

while ("%c == %%", &tem);

Code (Text):#include <stdio.h>

int main()

{

struct fraction

{

int num;

int den;

};

struct fraction n1,n2,n3;

char sign,tem;

int newDen,newNum;

{

printf("%s","Alvin Lee's Rational Tutorial Program.\n");

printf("\n\n");

printf("Please follow instructions carefully.");

printf("\n\n");

printf("Enter your operation like 1/2 + 1/4");

printf("\n\n");

printf("Enter % operator to stop the program (1/2 % 1/4)");

{

printf("\n\n");

printf("Please enter your operation:");

scanf("%d%c%d %c %d%c%d",&n1.num,&tem,&n1.den,&sign,&n2.num,&tem,&n2.den);

printf("\n\n");

if (sign == '+')

{

newDen = n1.den * n2.den;

newNum = n1.num*n2.den + n2.num*n1.den;

}

if (sign == '-')

{

newDen = n1.den * n2.den;

newNum = n1.num*n2.den - n2.num*n1.den;

}

if (sign == '/')

{

newDen = n1.den * n2.num;

newNum = n1.num*n2.den;

}

if (sign == '*')

{

newDen = n1.den * n2.den;

newNum = n1.num * n2.num;

}

printf("Please enter your result:");

scanf("%d%c%d", &n3.num,&tem,&n3.den);

if(n3.num==newNum && n3.den==newDen)

printf("\nCongratulations! It is correct: %d/%d\n",newNum,newDen);

else

printf("\nIt is incorrect. The correct answer is: %d/%d\n",newNum,newDen);

}

printf("Its floating point value is: %f", (float)newNum / (float)newDen);

}

return 0;

}

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: Applying a do while loop to my program

**Physics Forums | Science Articles, Homework Help, Discussion**