C++ help

C

C++Geek

IfIf anyone can help with this I would greatly appreciate it. I have
written the following code but get an error message that reads "term
does not evaluate to a function". The errors are on lines 36 & 37.
Thank you

#include <iostream>
#include <iomanip>
const int stu_num = 10, quiz_num = 8;


void st_ave(const int grade[][quiz_num], double st_ave[]);


void quiz_ave(const int grade[][quiz_num], double quiz_ave[]);



void display(const int grade[][quiz_num],
const double st_ave[], const double
quiz_ave[]);

int main( )
{
using namespace std;
int grade[stu_num][quiz_num];
double st_ave[stu_num];
double quiz_ave[quiz_num];

for(int i=0; i< stu_num; i++)

{
cout<<"enter grades for students"<<i+1;


for(int j=0; j <quiz_num; j++)
cin>>grade[j];


}


st_ave(grade, st_ave);
quiz_ave(grade, quiz_ave);
display(grade, st_ave, quiz_ave);
return 0;
}


void st_ave(const int grade[][quiz_num], double st_ave[])
{
for (int st = 1; st <= stu_num; st++)
{
double sum = 0;
for (int qu = 1; qu <= quiz_num; qu++)
sum = sum + grade[st-1][qu-1];
st_ave[st-1] = sum/quiz_num;

}
}


void quiz_ave(const int grade[][quiz_num], double quiz_ave[])
{
for (int qu= 1; qu <= quiz_num; qu++)
{
double sum = 0;
for (int st = 1; st <= stu_num; st++)
sum = sum + grade[st-1][qu-1];

quiz_ave[qu-1] = sum/stu_num;
}
}

//Uses iostream and iomanip:
void display(const int grade[][quiz_num],
const double st_ave[], const double
quiz_ave[])
{
using namespace std;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1);

cout << setw(10) << "Student"
<< setw(5) << "Ave"
<< setw(15) << "Quizzes\n";
for (int st = 1; st <= stu_num; st++)
{
cout << setw(10) << st
<< setw(5) << st_ave[st-1] << " ";
for (int qu = 1; qu <= quiz_num; qu++)
cout << setw(5) << grade[st-1][qu-1];
cout << endl;
}

cout << "Quiz averages = ";
for (int qu = 1; qu <= quiz_num; qu++)
cout << setw(5) << quiz_ave[qu-1];
cout << endl;
}
 
N

Neelesh Bodas

C++Geek said:
IfIf anyone can help with this I would greatly appreciate it. I have
written the following code but get an error message that reads "term
does not evaluate to a function". The errors are on lines 36 & 37.
Thank you

[multiple posting]
Since this is a newsgroup and a not a chat session, posting more than
once doesnot really help.
void st_ave(const int grade[][quiz_num], double st_ave[]);


void quiz_ave(const int grade[][quiz_num], double quiz_ave[]);
[code snipped]
int main( )
{
using namespace std;
int grade[stu_num][quiz_num];
double st_ave[stu_num];
double quiz_ave[quiz_num];

[rest code snipped ]

The error is due to the fact that you have local variables in your main
function whose names are same as the functions st_ave() and quiz_ave().
Try changing either of them and the code will work.
 
V

Victor Bazarov

C++Geek said:
IfIf anyone can help with this I would greatly appreciate it. I have
written the following code but get an error message that reads "term
does not evaluate to a function". The errors are on lines 36 & 37.
Thank you

Something is wrong with your newsgroup software. Three identical posts
from you...

BTW, which lines are 36 and 37?
#include <iostream>
#include <iomanip>
const int stu_num = 10, quiz_num = 8;


void st_ave(const int grade[][quiz_num], double st_ave[]);


void quiz_ave(const int grade[][quiz_num], double quiz_ave[]);



void display(const int grade[][quiz_num],
const double st_ave[], const double
quiz_ave[]);

int main( )
{
using namespace std;
int grade[stu_num][quiz_num];
double st_ave[stu_num];

You're declaring an array named the same as the function outside.
This variable ('st_ave') *hides* the name of the function.
double quiz_ave[quiz_num];

Same story.
for(int i=0; i< stu_num; i++)

{
cout<<"enter grades for students"<<i+1;


for(int j=0; j <quiz_num; j++)
cin>>grade[j];


}


st_ave(grade, st_ave);


Here you're trying to call the function. Instead 'st_ave' is resolved
as the name of the array in this scope. You need to add '::' in front
of the name:

::st_ave(grade, st_ave);
quiz_ave(grade, quiz_ave);

Same recommendation

::quiz_ave(grade, quiz_ave);
display(grade, st_ave, quiz_ave);
return 0;
}


[...]

Of course, it is much better to avoid such name conflicts and never give
the same name to your variables as some functions (or other variables
for that matter).

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top