我不断收到此错误,并不明白为什么有些东西没有返回。我试图改变一些东西,但它似乎没有做任何事情。我告诉程序返回0给用户,但由于某种原因,这仍然是一个问题。任何帮助将不胜感激。谢谢!为什么我一直得到 - 警告:控制达到非无效功能的结束[-Wreturn-type]
代码:
#include <iostream>
using namespace std;
char grade(int x)
{
if (x >= 90) {
return 'A';
}
if (x >= 80) {
return 'B';
}
if (x >= 70) {
return 'C';
}
if (x >= 60) {
return 'D';
}
if (x >= 0) {
return 'F';
}
}
int main(void)
{
int s_grade; // student grade
cout << "What is the score: ";
cin >> s_grade;
cout <<"A score of " << s_grade << " is equal to a grade of " <<
grade(s_grade) << endl;
return 0;
}
['使用命名空间标准;'是一个不好的做法](https://stackoverflow.com/q/1452721/2176813),永远不要使用它。此外,在C++中,如果函数没有参数(没有它通常被认为更具代表性),则不必在参数列表中放置'void' – tambre
如果'x'小于零,返回'grade' ? – 1201ProgramAlarm
如果没有你的'if's执行你不返回任何东西 – user463035818