I am trying to code a calculator in C and it works fine, but the second time I run it, it doesn't work. I've tried renaming the label I use to restart the program, I've tried putting the label in a different place, I've tried putting the label in a different place. I am running windows 10.
Here's my code:
#include <stdio.h>
int main ()
{ //main body
char calctype; //adding variables
double userinput, input2; //adding variables
Loop:
printf ("\n");
printf("Hi! Welcome to the calculator. Please enter a calculating type to continue. (+, -, *, /).");
scanf ("%c,", &calctype);
printf("\n");
printf ("Next, enter your numbers.");
scanf ("%lf %lf", &userinput, &input2);
switch (calctype)
{ //main body 2
case '+':
printf ("%.1lf + %.1lf = %.1lf", userinput, input2, userinput + input2); /*detecting operator
and calculating */
break;
case '-':
printf ("%.1lf - %.1lf = %.1lf", userinput, input2, userinput - input2);
break;
case '*':
printf ("%.1lf * %.1lf = %.1lf", userinput, input2, userinput * input2);
break;
case '/':
printf ("%.1lf / %.1lf = %.1lf", userinput, input2, userinput / input2);
break;
default:
printf ("The specified operator is not defined");
break;
}
goto Loop;
return 0;
}
Here is the output:
Hi! Welcome to the calculator. Please enter a calculating type to continue. (+, -, *, / ).+
Next, enter your numbers.
12345 1234
12345.0 + 1234.0 = 13579.0
Hi! Welcome to the calculator. Please enter a calculating type to continue. (+, -, *, / ).+
Next, enter your numbers.The specified operator is not defined
Hi! Welcome to the calculator. Please enter a calculating type to continue. (+, -, *, / ).