如何提示用户输入一定数量的整数 [英] How to prompt the user to enter a integer within a certain amount of numbers
本文介绍了如何提示用户输入一定数量的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图弄清楚用什么语句让用户输入1到10之间的数字。
I was trying to figure out what statement to use to get the user to enter a number between 1 and 10.
这是我到目前为止所拥有的。
here is what i have so far.
int a;
printf("Enter a number between 1 and 10: \n);
scanf("%d", &a);
推荐答案
int input;
while (true){
scanf("%d",&input);
if (input>=1 && input<=10){
// process with your input then use break to end the while loop
}
else{
printf("Wrong input! try Again.");
continue;
}
}
这篇关于如何提示用户输入一定数量的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文