Why does the code get the empty data directly in even times? I have no idea what is going on. Thank you very much.
#include <stdio.h>
#pragma warning(disable : 4996)
void main() {
int f, a = 10, b = 20;
for (int i = 0; i < 5; i++)
{
char ch;
ch = getchar();
printf("ch = %c\n", ch);
switch (ch)
{
case '+': f = a + b; printf("f = %d\n", f); break;
case '−': f = a - b; printf("f = %d\n", f); break;
case '*': f = a * b; printf("f = %d\n", f); break;
case '/': f = a / b; printf("f = %d\n", f); break;
default: printf("invalid operator\n");
}
}
}
If I input one operator,it loops two time. And the second time is the empty input.