The program works fine up until after the first calculation. The program prompts the user to enter Y or N to calculate again. But scanf wont take the the input.
Also I know it would be better to use a loop instead of a goto statement but my book asks me to use the goto for now because it hasn't gotten to explaining loops yet.
Code:
/*Example 3.11 A calculator*/
#include<stdio.h>
int main()
{
double number1 = 0.0; /*first operand value a decimal number */
double number2 = 0.0; /*second operand value a decimal number */
char operation = 0; /*operation - must be +, -, *, /, or % */
char again = 0;
there: printf("\nEnter the calculation\n");
scanf("%lf %c %lf", &number1, &operation, &number2);
/*code to check the input goes here*/
switch(operation)
{
case'+':
printf("=%lf\n", number1 + number2);
break;
case'-':
printf("=%lf\n", number1 - number2);
break;
case'*':
printf("=%lf\n", number1 * number2);
break;
case'/':
if(number2 == 0)
printf("\n\n\aDivision by zero error!\n");
else
printf("=%lf\n", number1 / number2);
break;
case'%':
if((long)number2 == 0)
printf("\n\n\aDivision by zero error!\n");
else
printf("=%ld\n", (long)number1 % (long)number2);
break;
default:
printf("\n\n\aIllegal operation!\n");
break;
}
printf("\nWould you like to carry out another calculation Y or N? ");
scanf("%c", &again);
if(again == 'y' || again == 'Y')
goto there;
}