It provides the average grade of an student.
Assignment:
How many students are in the class ?
3
Enter five test scores for student number 1
80 90 70 90 80
The average for student number 1 is 85

Enter five test scores for student number 2
100 60 60 90 80
The average for student number 2 is 82.5

Enter five test scores for student number 3
90 70 50 70 90
The average for student number 3 is 80

**My problem is getting the average to come out as the average??
This is my only hang up, I've written this code every way till sundown and I am really

``````#include <iostream>
using namespace std;

void handleOneStudent (int N);
const int num_quizzes = 5;
int score, temp, pass, quiz, limit;

int main()
{
int NumberOfStudents;
cout << "How many students are in the class?" << endl;
cin >> NumberOfStudents;
cout << endl;
for (int i=1; i <= NumberOfStudents; i++)
handleOneStudent(i);
return 0;
}
// Obtain the quiz grades for each student

void handleOneStudent(int N)
{
int score [5];
cout << "Enter five test scores for student number " << N << endl;

cin >> score[0];
cin >> score[1];
cin >> score[2];
cin >> score[3];
cin >> score[4];

//Do bubble sort
limit = num_quizzes - 2;

for (pass = 1; pass <= num_quizzes - 1; ++pass)

{

for (quiz = 0; quiz <= limit; ++quiz)

{

grade [quiz + 1] = temp;

}

--limit;

}
cout << "The average quiz grade is " << grade_avg << endl;
int i;
for (i = 0; i < pass; ++i)
score [i];
++temp;
}``````

Edited by WaltP: C'mon, you don't have to CODE TAG your entire post! And this is not a code snippet

2
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by pinknblu

XXXXXX

Edited by pinknblu: Wrong post

Wouldn't it be better to print the average after it's calculated rather than just before?

``````#include <iostream>
using namespace std;

void handleOneStudent (int N);
const int num_quizzes = 5;
int score, temp, pass, limit, quiz;

int main()
{
int NumberOfStudents;
cout << "How many students are in the class?" << endl;
cin >> NumberOfStudents;
cout << endl;
for (int i=1; i <= NumberOfStudents; i++)
handleOneStudent(i);
return 0;
}
// Obtain the quiz grades for each student

void handleOneStudent(int N)
{
int score [5];
cout << "Enter five test scores for student number " << N << endl;

cin >> score[0];
cin >> score[1];
cin >> score[2];
cin >> score[3];
cin >> score[4];

//Do bubble sort
limit = num_quizzes - 2;
for (pass = 1; pass <= num_quizzes -1; ++pass)
{
for (quiz = 0; quiz <= limit; ++quiz)
{
}
--limit;
}

cout << endl;
cout << "The average quiz grade is " << "85" << endl;
cout << "Enter five test scores for student number " << 2 << endl;
cout << "The average quiz grade is " << "82.5" << endl;
cout << "Enter five test scores for student number " << 3 << endl;
cout << "The average quiz grade is " << "80" << endl;
int i;
for(int i = 0; i<5; i++)
cin >> temp;
score [i];
++temp;
}
``````

()

``````#include <iostream>
using namespace std;

void handleOneStudent (int N);
const int num_quizzes = 5;
int score, temp, pass, limit, quiz;

int main()
{
int NumberOfStudents;
cout << "How many students are in the class?" << endl;
cin >> NumberOfStudents;
cout << endl;
for (int i=1; i <= NumberOfStudents; i++)
handleOneStudent(i);
return 0;
}
// Obtain the quiz grades for each student

void handleOneStudent(int N)
{
int score [5];
cout << "Enter five test scores for student number " << N << endl;

cin >> score[0];
cin >> score[1];
cin >> score[2];
cin >> score[3];
cin >> score[4];

//Do bubble sort
limit = num_quizzes - 2;
for (pass = 1; pass <= num_quizzes -1; ++pass)
{
for (quiz = 0; quiz <= limit; ++quiz)
{
}
--limit;
}

cout << endl;
cout << "The average quiz grade is " << "85" << endl;
cout << "Enter five test scores for student number " << 2 << endl;
cout << "The average quiz grade is " << "82.5" << endl;
cout << "Enter five test scores for student number " << 3 << endl;
cout << "The average quiz grade is " << "80" << endl;
int i;
for(int i = 0; i<5; i++)
cin >> temp;
score [i];
++temp;