[英]My code is supposed to take in a number, and return either the letter grade or “Grade is not valid” but the else statement is not working
My code is supposed to take in a number, and return either the letter grade or "Grade is not valid" but the else statement is not working.我的代码应该接受一个数字,并返回字母等级或“等级无效”,但 else 语句不起作用。
#include<iostream>
using namespace std;
int main(){
int score = 0;
string response = "Grade is ";
cout<<"Please enter score: "<<endl;
cin>>score;
if(score<100 || score>0){
if (score>=0 && score<60)
cout<<response<<"F"<<endl;
if(score>=60 && score<70)
cout<<response<<"D"<<endl;
if(score>=70 && score<80)
cout<<response<<"C"<<endl;
if(score>=80 && score<90)
cout<<response<<"B"<<endl;
if (score>=90 && score<100)
cout<<response<<"A"<<endl;
}
else
cout<<"Not a valid score"<<endl;
}
Your logic is wrong.你的逻辑是错误的。 The score should be greater than or equal to 0 AND less than or equal to 100, not OR.
分数应大于或等于 0 AND 小于或等于 100,而不是 OR。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.