Little help please

C

C++Geek

I need the following code to take the actual number of students and
quizzes to be entered via the keyboard but to be less than the const
students (stu_num and quiz_num). the error messages I am getting are
as follows:

error C2065: 'size' : undeclared identifier
error C2065: 'grades' : undeclared identifier
error C2143: syntax error : missing ';' before '}'

Any help would be greatly appreciated


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

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

void func_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( )
nts and Setti
{
using namespace std;
int grade[stu_num][quiz_num];
double st_ave[stu_num];
double quiz_ave[quiz_num];


cout<<"enter number of students





"<<endl;
cin>>size;

cout<<"enter number of grades"<<endl;
cin>>grades;


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


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


for(int grades=0; grades <quiz_num; grades++)



}


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


void func_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 func_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;
}
 
G

GB

C++Geek said:
I need the following code to take the actual number of students and
quizzes to be entered via the keyboard but to be less than the const
students (stu_num and quiz_num). the error messages I am getting are
as follows:

error C2065: 'size' : undeclared identifier
error C2065: 'grades' : undeclared identifier
error C2143: syntax error : missing ';' before '}'

Any help would be greatly appreciated

Do you know what an undeclared identifier is? Before you can use an
identifier in your program, for example "size" in the statement

cin >> size;

you have to declare the type of "size" and define it somewhere. Usually
you do both of these things with one definition statement.

Gregg
 
S

Sandeep

C++Geek said:
I need the following code to take the actual number of students and
quizzes to be entered via the keyboard but to be less than the const
students (stu_num and quiz_num). the error messages I am getting are
as follows:

error C2065: 'size' : undeclared identifier
error C2065: 'grades' : undeclared identifier
error C2143: syntax error : missing ';' before '}'

Any help would be greatly appreciated


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

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

void func_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( )
nts and Setti
{
using namespace std;
int grade[stu_num][quiz_num];
double st_ave[stu_num];
double quiz_ave[quiz_num];


cout<<"enter number of students





"<<endl;
cin>>size;

You are using variable "size" before declaring it.
cout<<"enter number of grades"<<endl;
cin>>grades;

Same with "grade"
for(int size=0; size< stu_num; size++)
move declaration of size outside for loop and before you are using it ,
do the same with declaration of grade
{
cout<<"enter grades for students"<<size+1;


for(int grades=0; grades <quiz_num; grades++)

{
//what do you want to do with this "for" loop.
}
}


func_st_ave(grade, st_ave);
func_quiz_ave(grade, quiz_ave);
display(grade, st_ave, quiz_ave);
return 0;
}
[snip]
 
H

hsharsha

The below code compiles and links. Please do check.
i have added declarations for size and grades and few other
modifications.....

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

void func_st_ave(const int grade[][quiz_num], double st_ave[]);
void func_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];

unsigned int size = 0;
cout<<"enter number of students"<<endl;
cin>>size;

unsigned int grades = 0;
cout<<"enter number of grades"<<endl;
cin>>grades;

for(size=0; size< stu_num; size++)
{
cout<<"enter grades for students"<<size+1;

for(int grades=0; grades <quiz_num; grades++)
{
/* I think u need to add some more cin statements */
}

}

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


void func_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 func_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;
}
 
D

Daniel T.

"C++Geek said:
I need the following code to take the actual number of students and
quizzes to be entered via the keyboard but to be less than the const
students (stu_num and quiz_num).

Everyone else showed you how to fix your error codes, but I don't see
where anyone helped you with the above...

Something like this would work:

while ( !( cin >> size ) || !( 0 < size && size < stu_num ) ) {
cout << "that was a bad numer, try a number between 0 and "
<< stu_num << " " << endl;
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n');
}

Does someone know of a cleaner way of dumping cin's buffer?
 
P

Peter_Julian

| cout the students and grades entered
|

Not good enough, one does not open the door to the car, sit in the
driver's seat and then construct the car. Doesn't it make sense that the
universe needs to know beforehand what type of car and what colour /
make / model it is?

Step outside with bare feet and see if the socks and shoes magicly
appear.
Try sleeping in an imaginary bed to see if a bed appears when you awake.
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top