#include <iostream>
using namespace std;
int main()
{
float score;
char grade;
cout<<"Please enter a score: ";
cin>>score;
if(score>100||score<0)
{
cout<<"Sorry,you have a wrong number,please enter again!"<<endl;
cout<<"Please enter a score: ";
cin>>score;
}
switch(int(score/10))
{
case10:
case 9:grade='A';break;
case 8:grade='B';break;
case 7:grade='C';break;
case 6:grade='D';break;
default:grade='E';
}
cout<<"Score is "<<score<<",grade is "<<grade<<endl;
return 0;
}
为什么输入100,运行结果出错,好像其他都正常
因为您漏了个空格。
case10:不是case标签,而是标号(所以语法没错,编译通过了,但程序有逻辑漏洞)。
改成
case 10: