我写了一个简单的平均计算程序,试图计算一个学期的平均数。当我编译代码时,我收到一个错误,告诉我我的“inputExam”函数没有在这个范围内声明。我已经研究了错误消息,但我不知道该怎么做才能修复它。
对于其他功能,我也遇到了这个错误,但是一旦我理解了我的错误,我想我可以修复其他功能。
#include <iostream>
using namespace std;
int main()
{
double finalExam=0.0;
double midterm = 0.0;
double quizzes = 0.0;
double labs = 0.0;
double semGrade=0.0;
midterm=inputExam("Midterm");
finalExam=inputExam("Final");
quizzes=inputAndAvgQuizzes();
labs=inputAndAvgLabs();
semGrade=(midterm*.2)+(finalExam*.2)+(labs*.5)+(quizzes*.1);
cout<<"Your End of Semester Grade is: " semGrade;
return 0;
}
double inputExam(string examType)
{
double grade;
cout<< "Enter the " examType " Score: ";
cin>>grade;
return (grade);
}
double inputAndAvgLabs()
{
double num [4];
double sum;
double avg;
if (int a=0, a<3,a++)
{
cout<<"What is the grade?"<<endl;
cin>>num[a]>>endl;
}
if (int a=0, a<3, a++)
{
sum=sum+num[a];
}
avg=sum/4;
return avg;
}
double inputAndAvgQuizzes()
{
double num[3];
double sum;
double avg;
double lowest = num[0];
if (int a=0, a<2,a++)
{
cout<<"What is the grade?"<<endl;
cin>>num[a]>>endl;
}
if (lowest>num[1])
{
lowest=num[1];
}
if (lowest>num[2])
{
lowest=num[2];
}
sum=num[1]+num[2]+num[3]-lowest;
avg=sum/2;
return avg;
}