Almost done with code, running into one problem.

The task is to write a C++ program that reads exam scores and displays the average score and the high score. I'm able to make the code do everything but display the highest score, and I'm just not sure how to approach it. Any help would be much appreciated!

#include<iostream>
#include<math.h>
using namespace std;

int main( )
{
int number_of_tests, number_of_scores, scores, number_of_tests_2, total_scores;
double average_score;

cout << "Enter number of tests.\n";
cin >> number_of_tests;

number_of_tests_2 = number_of_tests;

cout << "Enter all test scores.\n";
while (number_of_tests_2 > 0)
{
number_of_tests_2 = number_of_tests_2 -1;

cin >> scores;
total_scores = total_scores + scores;
}

average_score = total_scores / number_of_tests;

cout << "The average score is ";
cout << average_score;

return 0;
}
Add a variable maxScore = 0 and compare its value with each entry.
If it is less than the current entry then give it the value of that now highest entry.
Last edited on
Ah, I had the exact same task at school earlier.

Okay, so think about it like that:

When you get the first score, which score is the highest? Itself, the only one, of course.

Then, when you get another one, is it bigger or smaller? If it's bigger then update highscore.

I hope you understood.
Thanks so much, I'll try it. New to the code thing, so i appreciate it greatly.
Topic archived. No new replies allowed.