C++ Console Program - Determining highest and lowest score for diving competition.

I am currently writing a small program in VS17 for my c++ class. I'm sure you all have heard this 'diving' question multiple times before and are probably annoyed by it, but I am almost done ironing out my code and need help with only a small issue. My program compiles and is correct for the most part.

I've looked everywhere. I only seem to find code that determines the highest/lowest value for specific variables (score1,score2,score3,score4...etc) and arrays; however, I am looking to determine the highest/lowest score inside a loop (around line 33-40).'inputScore' assigns all the scores to 'totalScore' after asking the user 5 times for a judges score. In simpler terms, I am trying to analyze each input and determine if it is the running highest/lowest value to subtract later on in my program.

I hope this makes sense and I really appreciate anyone reading this and having a go to complete it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
	char continueLoop = 'Y';
	string diverName, diverCity;
	double highScore{ 0 }, lowScore{ 0 }, totalScore{ 0 }; //Initialize highscore, lowscore, totalscore
	double inputScore{ 0 };
	double diveDifficulty{ 0 };
	double avgScore{ 0 };
	double diverTotal{ 0 }, overallScore{ 0 };
	double allScores{ 0 };
	double saveTotal = totalScore;
	int numberDivers{ 0 }, numJudges{ 0 };

	cout << "\t\t\t\tReport to the media\n"; // Report Heading
	cout << "Event: Diving Competition\n";
        cout << "Press 'Enter' to begin the program...";

	while (continueLoop == 'Y' || continueLoop == 'y') // Start loop as long as there are divers to process
	{
		cin.ignore();
		cout << "\nEnter the diver's name: "; // Input divers name and city
		getline(cin, diverName);
		cout << "Enter the diver's city: ";
		getline(cin, diverCity);

		for (numJudges = 1; numJudges < 6; numJudges++) //Input score from 5 Judges
		{
			cout << "Enter the score given by Judge #" << numJudges << ": ";
			cin >> inputScore;
			while (inputScore < 0 || inputScore > 10) // Validate if the input score is between 0-10
			{
				cout << "Invalid score - Please reenter (Valid Range: 0 - 10)" << endl;
				cout << "Enter the score given by Judge #" << numJudges << ": ";
				cin >> inputScore;
			}
			totalScore += inputScore;//Add score to total
		}
		cout << "What was the degree of difficulty? "; //Input degree of difficulty
		cin >> diveDifficulty;
		while (1 > diveDifficulty || diveDifficulty > 1.67) // Validate degree of difficulty
		{
			cout << "Invalid degree of difficulty - Please reenter (Valid Range: 1 - 1.67)\n";
			cout << "What was the degree of difficulty? ";
			cin >> diveDifficulty;
		}
		
		diverTotal = totalScore - highScore - lowScore;
		overallScore = (diverTotal / 3) * diveDifficulty;
		totalScore = saveTotal;

		numberDivers++; // Add number of divers that have been processed
		allScores += overallScore; // Add divers score to overall 'running' score
		cout << "\nDiver: " << diverName << ", " << "City: " << diverCity << endl;// Display divers information and overall score
		cout << setprecision(3) << "Overall Score was " << overallScore;

		cout << "\n\nDo you want to process another diver (Y/N)?"; //Prompt user to process another diver y/n
		cin >> continueLoop;
	}//End loop if n or N input

	cout << "\n\tEvent Summary" << endl;
	cout << "Number of divers participating: " << numberDivers << endl;
	avgScore = allScores / numberDivers; //avg score calculated for all divers
	cout << setprecision(3) << "Average score of all divers: " << avgScore << endl; //display avg score of all divers and number of divers processed
	system("pause");

	return 0;
}
Last edited on
You could make two variables high and low for example and every time judge gives a score you could compare the new given score with the previous score and if it is higher(lower) than high(low) gets new score.
Topic archived. No new replies allowed.