help with functions using variables as arguments
Hi,
I am really new so if this is in the wrong place, I apologize in advance. I am having a problem with passing a value that is the return of one function as the argument of another. I thought I had the problem fixed, but I keep getting some errors. Could someone tell me where I have gone wrong?
Here is my code:
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double getInput();
double calAvg(double);
char getGrade(double );
void doAgain();
const int numStudents = 5;
const int numScores = 4;
int main ()
{
getInput();
doAgain();
}
double getInput()
{
char name [5] [25];
double score [4];
int count = 0;
double average[5];
for (count = 0; count < numStudents; count++)
{
cout << "Please enter your student's name and press enter:\n";
cin.getline(name [5],25);
cout << "Please enter his or her average scores and press enter\n";
for (count = 0; count < numScores; count++)
{
cin >> score[4];
if (score [4] < 0 || score[4] > 100)
{
cout << "Scores cannot be less than 0 or more than 100\n";
cout << "Please try again.";
break;
calAvg(score[4]);
getGrade(average[5]);
}
}
}
}
double calAvg()
{
double score [4];
double total;
double average[5];
for (int loop = 0; loop < numStudents; loop++);
{
total = 0;
total += (score[0] + score[1] + score [2] + score[3]);
average[5] = total / numScores;
cout << "This student's average is " << average[5];
system ("cls");
return (average[5]);
}
}
char getGrade()
{
for (int loop = 0; loop < numStudents; loop++);
{
if average[5] < 100 && average[5] > 90;
{
cout << "The student's grade is A";
}
if average[5] < 89 && average[5] > 80;
{
cout << "The student's grade is B";
}
if average[5] < 79 && average[5] > 70;
{
cout << "The student's grade is C";
}
if average[5] < 69 && average[5] > 60;
{
cout << "The student's grade is D";
}
if average[5] < 69 && average[5] > 0;
{
cout << "The student's grade is F";
}
}
}
void doAgain ()
{
char end;
cout << "Do You Want To Exit The Program? Please Press Y or y to end:";
cin >> end;
switch (end)
{
case 'Y':
case 'y': exit (1);
break;
default: main();
}
return;
}
Here are the errors I received:
Code:
Compiling...
gradebook.cpp
c:\documents and settings\____\my documents\visual studio 2005\projects\____\____\gradebook.cpp(80) : error C2061: syntax error : identifier 'average'
c:\documents and settings\____\my documents\visual studio 2005\projects\____\____\gradebook.cpp(84) : error C2061: syntax error : identifier 'average'
c:\documents and settings\____\my documents\visual studio 2005\projects\____\____\gradebook.cpp(88) : error C2061: syntax error : identifier 'average'
c:\documents and settings\____\my documents\visual studio 2005\projects\____\____\gradebook.cpp(92) : error C2061: syntax error : identifier 'average'
c:\documents and settings\____\my documents\visual studio 2005\projects\____\____\gradebook.cpp(96) : error C2061: syntax error : identifier 'average'
Build log was saved at "file://c:\Documents and Settings\____\My Documents\Visual Studio 2005\Projects\____\____\Debug\BuildLog.htm"
Please help.
Thanks in advance