所以这个程序应该根据你输入的百分比告诉你你的成绩,我基本上只使用 if 和 else 语句来编码它。该程序一直运行到 59%,然后当我输入高于该百分比的任何内容时,它就不起作用了。因为在程序中只是不会告诉我 59% 后的成绩。谢谢任何事情都会有帮助!!!
ps 我知道可能有一种更简单的方法可以编写这个程序,但我想练习 if 和 else 语句......
//
//exercise 1.
//you will enter in your percent and it will anounce your grade.
//create a program so that it will notify the user of their letter grade
//0-59 F 60-69 D 70-79 C 80-89 B 90-100 A
//a=user input
//For whatever reason the program seems to only work up to 59% and after that it doesn't work.
int a;
#include <iostream>
using namespace std;
int main()
{
cout<< "Enter in the percent of your grade and \n I will tell you your grade"<<endl;
cin>>a;
if(a==100)
{
cout<<"you scored a perfect A";
}
else
if(a<=59)
{
if(a<0)
{
cout<<"your really stupid";
}
else
cout<<"you failed";
}
else
if(a>=60)
{
if(a<=69)
{
cout<<"You got a D";
}
}
else
if(a>=70)
{
if(a<=79)
{
cout<<"you got a C";
}
}
else
if(a>=80)
{
if(a<=89)
{
cout<<"you got a B";
}
}
else
if(a>=90)
{
cout<<"you got an A";
}
}