I am having an interesting problem in scanf. It inputs the integers successfully but overlooks the character. In debugging I saw a strange value placed in the character variable. Kindly help me--
#include <stdio.h>
int main()
{
int a,b;
char op;
printf("Welcome To Command Based Calculator");
// printf("\n");
printf("Now enter two numbers");
scanf("%d",&a);
scanf("%d",&b);
printf("Select the desired operator");
// printf("%d",a);
// printf("%d",b);
scanf("%c",&op);
printf("%c\n",op);
printf("Its working");
scanf("%c", &op);
printf("the value in op--%c\n",op);
switch(op)
{
case '+':
printf("%d + %d = %d", a, b, a+b);
break;
case'-':
printf("%d - %d = %d", a, b, a-b);
break;
case'*':
printf("%d * %d = %d", a, b, a*b);
break;
case'/':
printf("%d / %d = %d", a, b, a/b);
break;
case'%':
printf("%d % %d = %d", a, b, a%b);
break;
default:
printf("Invalid Operator!");
break;
}
return 0;
}
the problem is in line 14