#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
char op;
float a, b;
printf("\n Operators are ( +,-,*,/,^) \n");
printf("Enter 0 to quit \n");
while(1)
{
printf("Enter your choice: \n");
scanf("%c", &op);
switch(op)
{
case '+':
printf(" Enter your two numbers: \n");
scanf("%f %f", &a, &b);
printf("%f + %f = %f", a, b, a+b);
break;
case '-':
printf(" Enter your two numbers: \n");
scanf("%f %f", &a, &b);
printf("%f - %f = %f", a, b, a-b);
break;
case '*':
printf(" Enter your two numbers: \n");
scanf("%f %f", &a, &b);
printf("%f x %f = %f", a, b, a*b);
break;
case '/':
printf(" Enter your two numbers: \n");
scanf("%f %f", &a, &b);
printf("%f / %f = %f", a, b, a/b);
break;
case '^':
printf(" Enter your two numbers: \n");
scanf("%f %f", &a, &b);
printf("%f ^ %f = %f", a, b, pow(a, b));
break;
case '0':
exit(0);
}
}
return 0;
}
This program is basically a switch case basic calculator. After the while loop start, the program prints "Enter your choice" twice instead of once, can anyone tell how to fix this. Apart from that it works fine. The while loop is for menu driven program.