"c"未在此范围内声明
'c' was not declared in this scope
在我的平均成绩代码中,我有字母等级a,b,c,d和f,但是当我尝试运行它时,我的字母没有在这个范围内声明。我不知道这意味着什么。
这是我的代码:
#include<iostream>
using namespace std;
string average(int g);
int main()
{
int grade;
cout << "Enter your grade:" << endl;
cin >> grade;
cout << "Your grade is a" << average(grade) << "!" << endl;
return 0;
}
string average(int g)
{
if (g >= 90 && g <= 100)
{
return a;
}
else if(g >= 80 && g <90)
{
return b;
}
else if (g > 70 && g < 80)
{
return c;
}
else if (g == 70)
{
return d;
}
else if (g < 70)
{
return f;
}
return 0;
}
你的程序中没有任何地方声明等级 - a,b,c,d,e,f。编译器怎么知道 a 代表等级 a,b 代表等级 b 等等。
你可能可以使用枚举来声明成绩,就像这样——
enum grades {a='a', b='b', c='c', d='d', e='e', f='f'};
还有其他方法可以做到这一点。无论你用什么来实现你的目标,你都需要根据你的决定修改你的程序。
相关文章:
- 错误:未在此范围内声明'reverse'
- 错误:"imread"未在此范围内声明
- 未在此范围内声明错误 'xy'
- Socklen_t未在此范围内声明
- 错误:'[' 之前预期的非限定 id 和错误:'users'未在此范围内声明
- "Main"已在当前范围内声明
- c++ 变量在宏的扩展中没有在这个范围内声明
- C++ 在编译过程中 strtok 函数 Eclipse 说没有在范围内声明?
- 'num1'未在此范围内声明
- 如何找到在本地范围内声明的变量的地址?
- NT状态未在此范围内声明
- 变量未在此范围内声明 数组线性搜索
- 包含文件中的 Typdef "未在此范围内声明"
- 'ClassName'和'ClassInstance'未在此范围内声明
- C++ 中的类之间的数据重新循环 - 错误:'<class name>'未在此范围内声明
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 如何修复错误:"vreinterpretq_u32_f64"未在此范围内声明 - 在Android上使用Eigen构建
- 如何修复C++中的"arrStud未在此范围内声明"错误
- 错误:"SHGetKnownFolderPath"未在此范围内声明
- 错误:'Sprite'未在此范围内声明