I've got a question about switch statements.
Here is my code:
#include<stdio.h>
int main()
{
float a=0.0f;
float b=0.0f;
char operation=0;
printf("Enter expression:");
scanf("%f %c %f",&a,&operation,&b);
switch(operation)
{
case '+':
printf("=%.2f\n",a+b);
break;
case '-':
printf("=%.2f\n",a-b);
break;
case '*':
printf("=%.2f\n",a*b);
break;
case '/':
if(b==0)
printf("\ndivision by zero error.\n");
else
printf("=%.2f\n",a/b);
break;
case '%':
if(b==0)
printf("\ndivision by zero error.\n");
else
printf("=%d\n",(int)a%(int)b);
break;
default:
printf("invalid operation\n");
break;
}
return 0;
}
And this is result about two different input, one right, one wrong.
Why, when I enter two letters instead of two numbers, does it go into the default case?
