I have a simple problem;
Here is the code :
#include<stdio.h>
main(){
int input;
printf("Choose a numeric value");
scanf("%d",&input);
}
我希望用户只能输入数字……所以它应该是这样的:
#include<stdio.h>
main(){
int input;
printf("Choose a numeric value");
do{
scanf("%d",&input);
}while(input!= 'something');
}
我的问题是我不知道在“something”中要替换什么……如何防止用户输入字母字符?
编辑
我刚刚得到了一些有趣的东西:
#include<stdio.h>
main(){
int input;
printf("Choose a numeric value");
do{
scanf("%d",&input);
}while(input!= 'int');
}
添加“int”将使循环保持运行,只要我输入数字。我尝试过“char”,但那没用...肯定有适用于字母的东西吧?:S 请回复! 谢谢你的帮助!