c - 当用户输入无效输入时,为什么我的程序会进入无限循环?
问题描述
#include <stdio.h>
int main() {
int input;
do {
printf("Welcome to the Arithmetic Quiz Program!\n\n");
printf("Please choose one of the following by entering the correspoding "
"number:\n\n");
printf("1. Give me an addition problem.\n");
printf("2. Give me a subtraction problem.\n");
printf("3. Give me a multiplication problem.\n");
printf("4. Quit.\n\n");
scanf(" %i", &input);
} while (input != 1 && input != 2 && input != 3 && input != 4);
return 0;
}
当我输入不是整数的东西(例如:'a'、'b'、..)时,结果如下:
解决方案
推荐阅读
- python - 工厂方法中是否需要接口类?
- python - 如何选择多个复选框然后将值存储在列表中?Python
- flutter - Flutter:在 performResize() 期间抛出了以下断言:垂直视口被赋予了无限的高度
- google-chrome - 是否可以使用 mkcert 创建一个证书供我在开发中的所有本地应用程序使用?
- javascript - typeorm 自引用一对多计数
- css - react-bootstrap 行和列定位错误
- android - 导航在导航抽屉android中不起作用
- python - 每次我完成一行时,俄罗斯方块都会变慢(Python,Turtle)
- java - 如何避免在 OutOfMemoryError 后停止实验?
- python - 提供的 API 密钥无效/Geocoding-Python