Hi, I am trying to create a calculator program that only allows the user three attempts, my actul calculator program works fine however i cant figure out where the while loop should go here is my attempt. When i compile it it runs through the calculator but stops after taken the second num!
Code:
#include <stdio.h>
main()
{
int num1, num2, sum;
int count=0;
char operation,dummy;
printf("Enter first number: "); /*retrieves first number from user */
scanf("%d", &num1);
printf("Enter operation (+ or - or * or /): "); /* retrieves operation from user */
scanf("%c%c%c",&dummy,&operation,&dummy);
printf("Enter second number: "); /*retrieves second number from user */
scanf("%d", &num2);
while(count<3)
if (operation == '+'){
sum = num1 + num2;
printf("The sum of %d and %d is %d", num1,num2, sum);
} /* if operation is +, will add numbers and show answer */
if(operation == '-'){
sum = num1-num2;
printf("Subtracting %d from %d is %d", num2,num1,sum);
}/* if operation is -, will subtract and show answer */
if (operation == '*'){
sum = num1 * num2;
printf("Multiplying %d by %d is %d", num1, num2, sum);
} /* if operation is *, will multiply and show answer */
if (operation == '/'){
sum = num1 / num2;
printf("Dividing %d by %d is %d", num1, num2, sum);
}
/* if operation is /, will divide and show answer */
count=count+1;
return 0;
}