My aim was to select + or - sign and then add or subtract 2 numbers.
But I didn't understand why after the entrance of the first number, it only prompts to enter operation sign but ignores to take input sign despite I didn't press a button.
#include<stdio.h>
main()
{
char sign;
int no1, no2;
int result= 0;
printf("Enter first number:" );
scanf("%d", &no1);
printf("no1 is %d\n", no1);
printf("\nEnter sign: '+' or '-' ");
sign = getchar();
printf("Enter second number: ");
scanf("%d", &no2);
printf("no2 is %d", no2);
if(sign == '+')
{
result= no1 + no2;
}
else if(sign == '-')
{
result= no1-no2;
}
else
{
printf("Enter a valid sign!\n");
}
printf("%d\n", result);
}