Originally Posted by
vart
your loop should include your calculation code... how else will it be repeated?
I put the switch case in the while loop, but when I enter the two desired operands, it gives me the default, "Error! That is not an operation option!"
Code:
# include <stdio.h>
int main()
{
int num1, num2;
char op;
int finished = 0;
printf("Simple Operations Calculator\n");
printf(" \n");
printf("Enter your desired operation (+, -, *, /): ");
scanf("%c", &op);
printf("Enter your two desired numbers: ");
scanf("%d%d", &num1, &num2);
switch(op)
{
case '+':
printf("num1 + num2 = %.2d\n", num1+num2);
break;
case '-':
printf("num1 - num2 = %.2d\n", num1-num2);
break;
case '*':
printf("num1 * num2 = %.2d\n", num1*num2);
break;
case '/':
printf("num1 / num2 = %.2d\n", num1/num2);
break;
default:
printf("Error! That is not an operation option.");
break;
}
while(!finished){
printf("Enter your desired operation (+, -, *, /): ");
scanf("%c", &op);
getchar();
printf("Enter your two desired numbers: ");
scanf("%d%d", &num1, &num2);
switch(op)
{
case '+':
printf("num1 + num2 = %.2d\n", num1+num2);
break;
case '-':
printf("num1 - num2 = %.2d\n", num1-num2);
break;
case '*':
printf("num1 * num2 = %.2d\n", num1*num2);
break;
case '/':
printf("num1 / num2 = %.2d\n", num1/num2);
break;
default:
printf("Error! That is not an operation option.");
break;
}
getchar();
return 0;
}
}