I am new to c language and I wanted to make a calculator so I wrote this code:
#include<stdio.h>
void main()
{
int x,y,z;
char m;
printf("enter the first number");
scanf("%d",&x);
printf("enter the second number");
scanf("%d",&y);
printf("enter the math operator");
scanf("%c",&m);
if (m == '+')
{
z=x+y;
printf("the answer is %d",z);
}
else if(m == '-')
{
z=x-y;
printf("the answer is %d",z);
}
else
{
printf("wrong symbol");
}
}
when I run the program it will ignore
scanf("%c",&m);
and
if (m == '+')
{
z=x+y;
printf("the answer is %d",z);
}
else if(m == '-')
{
z=x-y;
printf("the answer is %d",z);
}
and it will go straight to
else
{
printf("wrong symbol");
}
and it shows like this: https://i.stack.imgur.com/RmsWm.jpg please help.