I want to write a simple calculator in C but when I run this code it just gets my numbers and doesn't get my operator and goes out from the running window! and when I move my scanf operator to top of the other scanf, it works right! why?!!!!
float num1, num2;
char op;
scanf("%f", &num1);
scanf("%f", &num2);
scanf("%c", &op);
switch(op)
{
case '+':
printf("%f + %f = %f", num1, num2, num1 + num2);
break;
case '-':
printf("%f - %f = %f", num1, num2, num1 - num2);
break;
case '*':
printf("%f * %f = %f", num1, num2, num1 * num2);
break;
case '/':
printf("%f / %f = %f", num1, num2, num1 / num2);
break;
default :
printf("error");
}
return 0;