Question: how do i get the average to come out, correctly. The first avg., should be 85, next second one: 85.5, then student three: 80.
Here's my code:

#include <iostream>
#include <iomanip>
 
using namespace std;
 
 
void handleOneStudent(int N);
 
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;
}
void handleOneStudent(int N)
{
	const int num_quizzes = 5;
	int score[num_quizzes];
	double average;
 
	cout << setprecision(2)
		 << setiosflags(ios::fixed)
		 << setiosflags(ios::showpoint);
 
	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];
 
	average = (score[1] + score[2] + score[3] + score[4] + score[5])/5;
	cout << endl << endl;
 
	cout << "The average for student number " << N << " is " << average << endl;
 
}

Edited 6 Years Ago by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

Code tags. Use them.

[code]

// code here

[/code]

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];

average = (score[1] + score[2] + score[3] + score[4] + score[5])/5;
cout << endl << endl;

Look at the indexes that you use when you read in the data versus the indexes you use when you do the calculation.

Edited 6 Years Ago by VernonDozier: n/a

I could ask u the same thing. I came here for input, nothing more. If you don't have any please don't respond. thanks. In any event if u were on a mission to help thanks, but help more so would be appreciated with my program, thanks again.

Comments
I agree with Vernon
Bad attitude

I could ask u the same thing. I came here for input, nothing more. If you don't have any please don't respond. thanks. In any event if u were on a mission to help thanks, but help more so would be appreciated with my program, thanks again.

Don't have any input to your problem? What the hell are you talking about? I saw the problem and pointed you in the right direction. Your problem is that you take input into indexes 0 through 4 and add indexes 1 though 5. There's no input in index 5. You don't use index 0. Therefore expect bad results. That was the whole point of my post. If you didn't understand that, you should have asked for clarification, not posted a smart-aleck comment.

And yes, post in code tags. I showed you how. Not sure what your problem is.

Edited 6 Years Ago by VernonDozier: n/a

Thanks, for the neg. raters. lol.

Anyway, a more valid input would be suggestions to my code, other than that your time is a waste...and a chuckle.

Heres some of my code: A ruff draft:

Needs work..."Real" Input would be appreciated.

#include <iostream>
using namespace std;

void handleOneStudent (int N);
const int num_quizzes = 5;
int grade [num_quizzes];
int limit, temp, pass, 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

handleOneStudent(int N) (int quiz_sum)
{
    cout << "Enter five test scores for student number " << N << endl;
    int num_quizzes = 5;
    for (quiz = 0; quiz < num_quizzes; ++quiz);
    {
        cin >> grade[quiz];
    }
}

// Do the Bubble Sort

    limit = num_quizzes - 2;
    for (pass = 1; pass <= num_quizzes -1; ++pass)
    {
        for (quiz = 0; quiz <= limit; ++quiz)
            if (grade[quiz] > grade[quiz - 1])
                {
                    temp = grade[quiz];
                    grade[quiz] - grade[quiz + 1];
                    grade[quiz + 1] = temp;
                }
        --limit;
    }
// Display the average grades
    {
        quiz_average = (grade[1] + grade[2] + grade[3] + grade[4] / 4.0;
    }
    cout << endl << endl;
    cout "The average for student number  << N << is " << quiz_average;
    cout << endl << endl;
}

Edited 6 Years Ago by Nick Evan: Fixed code-tags (again: it's [/CODE] NOT /CODE] )

Once again, I told you exactly what your problem is. If you had followed my advice, your program would be working. If giving advice that will make a non-working program work isn't "valid" advice, I don't know what you are looking for.

But you're right. Helping you is a waste of time. It will be better spent helping those who are willing to learn.

Assume score input is 30,40,50,60,70.
In your FOR loop, when quiz == 0, what value is element grade[quiz-1]?

Thanks WaltP...I'll examine your input once I get back to crackin' on my program again and report back.

This article has been dead for over six months. Start a new discussion instead.