我收到"无效类型 int[int]...",但这毫无意义
I'm Receiving 'Invalid Type Int[Int]...', But It's Making No Sense
我需要完成一个程序,其中您的数组包含十个测试分数。然后,您将该数组通过一个函数传递,该函数将显示十个中的最高分数。
#include <iostream>
using namespace std;
void showValue(int);//Function prototype
int main()
{
const int results = 10;
double tscores[results];
int result;
//Get the ten test scores from the user.
cout << "Please enter the ten test scores." << endl;
cin >> tscores[0];
cin >> tscores[1];
cin >> tscores[2];
cin >> tscores[3];
cin >> tscores[4];
cin >> tscores[5];
cin >> tscores[6];
cin >> tscores[7];
cin >> tscores[8];
cin >> tscores[9];
//Now, the program should pass the arry through a
//function to find the highest test score.
int max = 0;
for (int i = 0; i < results; i++)
{
if (result[0] > max)
{
max = result[0];
}
}
cout << "The highest score is " << max << endl;
return 0;
}
这些是我得到的错误:
Prog4r.cpp: In function ‘int main()’:
Prog4r.cpp:37:16: error: invalid types ‘int[int]’ for array subscript
Prog4r.cpp:39:19: error: invalid types ‘int[int]’ for array subscript
我似乎无法解决问题。任何帮助将不胜感激。
在下面的代码中,您尝试从名为 result
的变量访问索引,该变量不是数组。
if( result[0] > max )
{
max = result[0];
}
这里有一些错误,
- 您想要访问名为
tscores
的数组变量。- 您希望使用循环变量而不是 0。
- 变量
max
的类型应与tscores
相同。
double max = 0.0;
for( int i = 0; i < results; ++i )
{
if ( tscores[i] > max )
{
max = tscores[i];
}
}
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- int(c) 和 c-'0' 之间的区别。C++
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 函数重载毫无意义吗
- x86 - 为什么编译器在下一条指令中插入看似毫无意义的JMP?
- OpenGL 中的动态加载着色器毫无意义吗?
- 如果编译器只能执行恒定折叠,则是毫无意义的
- 在同一调用中打印 %n 的值 - 毫无意义?
- Netbeans 中的C++:许多毫无意义的"unexpected token"提示
- C++结构 - 毫无意义?
- 我收到"无效类型 int[int]...",但这毫无意义
- 常量工会成员有什么用?他们不是毫无意义吗?
- OpenCV中int main(int argc,char**argv)中argc和argv的意义
- 使用 std::unordered_map<int, int> 而不是 std::map<int, int> 有意义吗?
- C++:"vector<int>::size_type variable"——以这种方式声明有什么意义?
- 在字面意义上将字符串转换为 int
- 将函数的返回类型声明为 T&&& 是否毫无意义?
- CUDAMemcpy对我来说毫无意义…为什么要在普通c++中指定设备内存?