void display_totals();
int exam1[100][3];// array that can hold 100 numbers for 1st column
int exam2[100][3];// array that can hold 100 numbers for 2nd column
int exam3[100][3];// array that can hold 100 numbers for 3rd column
int main()
{
int go,go2,go3;
go=read_file_in_array;
go2= calculate_total(exam1[],exam2[],exam3[]);
go3=display_totals;
cout << go,go2,go3;
return 0;
}
void display_totals()
{
int grade_total;
grade_total=calculate_total(exam1[],exam2[],exam3[]);
}
int calculate_total(int exam1[],int exam2[],int exam3[])
{
int calc_tot,above90=0, above80=0, above70=0, above60=0,i,j;
calc_tot=read_file_in_array(exam[100][3]);
exam1[][]=exam[100][3];
exam2[][]=exam[100][3];
exam3[][]=exam[100][3];
for(i=0;i<100;i++);
{
if(exam1[i] <=90 && exam1[i] >=100)
{
above90++;
cout << above90;
}
}
return exam1[i],exam2[i],exam3[i];
}
int read_file_in_array(int exam[100][3])
{
ifstream infile;
int num, i=0,j=0;
infile.open("grades.txt");// file containing numbers in 3 columns
if(infile.fail()) // checks to see if file opended
{
cout << "error" << endl;
}
while(!infile.eof()) // reads file to end of line
{
for(i=0;i<100;i++); // array numbers less than 100
{
for(j=0;j<3;j++); // while reading get 1st array or element
infile >> exam[i][j];
cout << exam[i][j] << endl;
}
}
infile.close();
return exam[i][j];
}
回答
你传递到calculate_total的数据类型是错误的。 C++将它看作是一个指向int的指针。你传入一个二维数组。您必须使calculate_total函数的输入类型与您的数组类型相匹配。
此外,所有这些extra []的语法都是无效的。当传入定义为数组的变量时,只传入变量名称。
// Invalid function call
f(myArray[]);
// Valid function call
f(myArray);
在实际功能里面,你在做什么?您是否试图将考试1,考试2和考试3的元素修改为考试[100] [3]的值?您还缺少数组int exam[100][3]
的声明。我在代码中看不到它。
而在calculate_total的返回中,您的return语句格式错误。你只能返回一个值,不像Python那样会返回一个包含三个元素的元组。
return语句不是不合格的,它可能不符合预期。它使用逗号运算符,只是丢弃除最后一个值之外的所有值。 – 2010-04-29 04:35:54
即时通讯尝试从我读取的文本文件中对数组中的数字进行排序。像100-90是A,90-80是B等等。然后转到下一列,做同样的事情,然后第三个和所有的A,B,C,D,F和所有的结果在屏幕上打印 – user320950 2010-04-29 05:14:53
我应该使用我和j而不是100和3 – user320950 2010-04-29 05:40:39
我发现以下的问题在你的代码
read_file_in_array需要括号。 go = read_file_in_array; //无效的函数调用
数组参数
display_totals需要括号
函数原型在开始
display_totals将返回什么人失踪。但是你将它分配给一个变量
我不明白这个calculate_total函数在做什么。
如果这是您的原始代码,则此代码中存在很多问题。我按照原样使用了这些代码,并使用Turbo C++编译器进行编译。我得到了大约24个错误。
你可以请你重构你的代码并编译它。
我得到这些错误C2059:语法错误:'],我不知道为什么 – user320950 2010-04-29 05:43:31
这是你的完整源代码吗?如果不是,你可以分享你得到这个错误的确切代码。 – Dinesh 2010-04-29 07:32:08
- 1. Python SQlite3语法错误 - 无法弄清楚什么是错的
- 2. MySQL的语法错误,无法弄清楚什么是错
- 3. fileIn,fileOut错误 - 我无法弄清楚
- 4. 我无法弄清楚的sql错误
- 5. 我无法弄清楚什么是错
- 6. 我似乎无法弄清楚为什么这个查询给我错误
- 7. C#LINQ错误,无法弄清楚问题是什么
- 8. 获取分段错误。无法弄清楚为什么
- 9. UpdatePanel的错误 - 无法弄清楚
- 10. jQuery的错误 - 无法弄清楚,我犯了一个错误
- 11. 错误:C2059:语法错误:'{'
- 12. 无法弄清楚如何解决这个错误在Python类
- 13. 我无法弄清楚什么是错在我更新代码
- 14. 似乎无法弄清楚这个JES错误,谁知道?
- 15. 我似乎无法弄清楚我做错了什么?
- 16. “无法识别的选择器”错误。无法弄清楚
- 17. “错误:没有操作员的cin >>”我无法弄清楚我在做什么错在这里
- 18. C++类重新定义错误 - 我无法弄清楚为我的生活
- 19. EXEC()的错误,我无法弄清楚如何使它工作
- 20. 无法弄清楚我是如何得到seg错误
- 21. 的NodeJS - MongooseJS模式的错误,我无法弄清楚
- 22. 我无法弄清楚克隆在C#
- 23. 无法弄清楚什么是错我的CSS
- 24. PHP - > MySQL查询无法弄清楚什么是错得到错误#1064
- 25. 错误C2059:语法错误:“ - >”和“;”
- 26. 一般性错误+ ExternalException当时陷入无法弄清楚,为什么
- 27. '输入'没有命名类型错误。无法弄清楚为什么?
- 28. C2059语法错误'string'?
- 29. C2059:语法错误:常量
- 30. ,我无法弄清楚
errorerror?这听起来比一个正常的错误更严重:-) – paxdiablo 2010-04-29 04:17:43
你的错误是什么? – 2010-04-29 05:40:33
30-33,27是我遇到问题的线 – user320950 2010-04-29 05:52:58