After typing the second number you press enter, right? %c
in scanf accepts the first character it finds, so it returns the line break character corresponding to you pressing enter.
An easy fix is to add a space character before %c
. It makes scanf
skip any whitespace.
scanf(" %c",&op);
From the scanf documentation (http://www.cplusplus.com/reference/cstdio/scanf/):
Whitespace character:
The function will read and ignore any whitespace characters encountered before the next non-whitespace character (whitespace characters include spaces, newline and tab characters — see isspace). A single whitespace in the format string validates any quantity of whitespace characters extracted from the stream (including none).
1
solved Work With Char Using If else in C Language