win中,行开头输入 Ctrl + Z 代表EOF
你的程序中,输入Ctrl + Z后scanf读取不成功,a的值并不会改变,所以while (a!=EOF)无法中断
要改为在scanf处判断是否读取成功再决定是否结束循环#include <stdio.h>
int main() {
int a, b, answer;
char value;
int i = 0;
do {
printf("Please a value b:\n");
if (scanf("%d%c%d", &a, &value, &b) != 3) break;
switch (value) {
case '+':
answer = a + b;
break;
case '-':
answer = a - b;
break;
case '*':
answer = a * b;
break;
case '/':
answer = a / b;
break;
default:
i = 0;
printf("Input error!,please en-enter!:");
}
printf("%d%c%d=%d\n", a, value, b, answer);
} while (1);
return 0;
}
|