Im trying to make a calculator but encountering error the scanf("%c",&op); doesnt take up the character on compiling the program I also tried with op=getchar(); but doesnt work either
int main()
{
int num1,num2,result;
char op;
printf("Enter the first number\n");
scanf("%d",&num1);
printf("Enter the operation\n");
scanf("%c",&op);
printf("Enter the second number\n");
scanf("%d",&num2);
switch(op)
{
case '+' :
result=num1+num2;
printf("The addition of %d and %d is %d",num1,num2,result);
break;
case '-' :
result=num1-num2;
printf("The subtraction of %d and %d is %d",num1,num2,result);
break;
case '*' :
result = num1*num2;
printf("The multiplication of %d and %d is %d",num1,num2,result);
break;
case '/' :
result=num1/num2;
printf("The division of %d and %d is %d",num1,num2,result);
break;
default :
printf("Invalid operation");
}
return 0;
}