首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将字母等级转换为数字等级

将字母等级转换为数字等级
EN

Stack Overflow用户
提问于 2018-02-28 12:19:14
回答 1查看 1K关注 0票数 0

所以我在我的一个作业上遇到了一些麻烦。我需要让用户输入字母等级(B,B+/-),并将其转换为数字等级(3,2.7)。我可以让程序只与A,B,C一起工作,但我想不出当用户在分数上加一个+/-时,如何让程序工作。这就是我到目前为止所拥有的。

代码语言:javascript
复制
# 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;
   }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-28 12:23:04

您不需要变量AB等。而且,string A-;不是一个有效的声明。您可以简单地删除它们。

代码语言:javascript
复制
int main()
{
   string input;

   cout << "Enter a letter grade: ";

   cin >> input;

   if (input == "A")
       cout << "The numeric value is 4.0" <<endl;

   ...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49021916

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档