所以我在我的一个作业上遇到了一些麻烦。我需要让用户输入字母等级(B,B+/-),并将其转换为数字等级(3,2.7)。我可以让程序只与A,B,C一起工作,但我想不出当用户在分数上加一个+/-时,如何让程序工作。这就是我到目前为止所拥有的。
# include <iostream>
using namespace std;
int main()
{
string input;
string A;
string A-;
//string B+;
string B;
//string B-;
//string C+;
string C;
//string C-;
//string D+;
string D;
//string D-;
string F;
cout << "Enter a letter grade: ";
cin >> input;
if (input == "A")
cout << "The numeric value is 4.0" <<endl;
if (input == "A-")
cout << "The numeric value is 3.7" << endl;
if (input == "B+")
cout << "The numeric value is 3.3" << endl;
if (input == "B")
cout << "The numeric value is 3" <<endl;
if (input == "C")
cout << "The numeric value is 2" <<endl;
if (input == "D")
cout << "The numeric value is 1" <<endl;
if (input == "F")
cout << "The numeric value is 0" <<endl;
return 0;
}发布于 2018-02-28 12:23:04
您不需要变量A、B等。而且,string A-;不是一个有效的声明。您可以简单地删除它们。
int main()
{
string input;
cout << "Enter a letter grade: ";
cin >> input;
if (input == "A")
cout << "The numeric value is 4.0" <<endl;
...
}https://stackoverflow.com/questions/49021916
复制相似问题