In your code, please change
scanf("%f",&a);
scanf("%c",&op);
scanf("%f",&b);
scanf("%f",&r);
to
scanf("%f",&a);
scanf(" %c",&op); //notice here
scanf("%f",&b);
scanf("%f",&r);
Without the leading space before %c
, the \n
stoted by previous ENTER key press after previous input, will be read and considered as valid input for %c
format specifier. So, the second scanf()
will not ask for seperate user input and the flow will continue to the third scanf()
.
The whitespace before %c
will consume all leading whitespace like char
s, including the \n
stoted by previous ENTER key press and will consider only a non-whitespace input.
Note:
-
%f
format specifier reads and ignores the leading\n
, so in that case, you don’t need to provide the leading space before%f
explicitly. -
The signature of
main()
isint main(void)
.