我完成了上课的代码,但是我在函数下的括号中不断出现错误,我在上课时做到了,这不是问题。你们知道我在做什么错吗?我尝试过查找,但是我找不到真正解决特定问题的具体解决方案。
#include <iostream>
using namespace std;
int getGrades(int[], int);
void calcStats(int[], int, int&, int&, double&);
int main()
{
const int size = 20;
int grades[size];
int count = getGrades(grades, size);
int highGrade = 0;
int lowGrade = 100;
double average = 0;
calcStats(grades, count, highGrade, lowGrade, average);
cout << "Lowest Grade: " << lowGrade << endl;
cout << "Highest Grade: " << highGrade << endl;
cout << "Average Grade: " << average << endl;
system("pause");
return 0;
}
int getGrades(int Grades[], int size);
{ // error "expected a declaration"
int count = 0;
int grade;
cout << "Please enter up to 20 grades followed by a -1 when done." << endl;
cin >> grade;
while (grade != -1)
{
grades[count] = grade;
count++;
if (count == 20) {
break;
}
cin >> grade;
}
return count;
}
void calcStats(int grades[], int size,int& highGrade, int& lowGrade, double& average);
{ // error "expected a declaration"
int total = 0;
highGrade;
lowGrade;
for (int i = 0; i < size; i++) {
total += grades[i];
if (grades[i] > highGrades) {
highGrades = grades[i];
}
if (grades[i] < lowGrades) {
lowGrades = grades[i];
}
}
average = static_cast<double>(total) / size;
}
答案 0 :(得分:2)
您的前向声明后面有半冒号是正确的:
Children
如上面的评论所指出,定义本身不应该带有分号,而只能是大括号:
int getGrades(int[], int);
void calcStats(int[], int, int&, int&, double&);
一个不错的经验法则是,如果您使用牙套,则无需使用分号。
您的int getGrades(int Grades[], int size) // no semi colon
{ // error "expected a declaration"
}
函数似乎也带有getGrades
而不是Grades
的错字,但是我认为这是从您的IDE到此处问题的笔录错误,与您的问题无关问题。