I am making a simple calculator using if else statement, but my 2nd scanf where the user is giving the input as choosing the operator, it is not taking the input there.
// making a calculator
#include<stdio.h>
int main()
{
int a,b;
int ans;
char c;
printf("Enter your first number: \n");
scanf("%d", &a);
printf("Enter the operator '+','-','*','/': \n");
scanf("%c", &c); //isn't taking the input here
printf("Enter your second number: \n");
scanf("%d", &b);
if (c == '+')
{
ans = a+b;
printf("Your answer is: %d",ans);
}
else if (c == '-')
{
ans = a-b;
printf("Your answer is: %d", ans);
}
else if (c == '*')
{
ans = a*b;
printf("Your answer is: %d", ans);
}
else if (c == '/')
{
ans = a/b;
printf("Your answer is: %d", ans);
}
else
{
printf("Invalid input");
}
return 0;
}
all is okay but the the input where the user will put the operator isn't taking the input.