Can I get some help with this C++ program on functions. You have been selected t
ID: 3669685 • Letter: C
Question
Can I get some help with this C++ program on functions.
You have been selected to write a program to calculate the scores for a local diving competition. There are 6 judges who are rating each diver on a scale of 1 to 10. Scores can be entered up to 2 decimal places. You are going to write a program that will read in the scores and determine the average score. Your program will also determine the highest and lowest score given to each diver. Your program should implement functions that perform the following tasks: Accept the data - function should prompt the user for the judge's score. Error checking should validate that it is in the range of 1 to 10. The function should be called for each of the scores. Determine the highest score - return the highest score of all the scores passed to the function Determine the lowest score - return the lowest score of all the scores passed to the function Average the scores - display the average score of all the scores passed to the function. Keep the following points in mind when creating your program: Output should be labeled, aligned, and formatted to 2 decimal places. Do not use global variables in your program. Make sure you are using the correct data types and descriptive variable names. Add a comment to the top of your program that includes your name, the program name, and a description of the program code. Include descriptive comments throughout your program. Test your calculations!Explanation / Answer
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
int judge = 1;
double score, average,overallAverage;
double total = 0;
double totalAverage = 0;
char mainLoop = 'y';
int loop = 1;
double difficulty = 0;
double max = 0;
double min = 0;
string DiverName;
string DiverCity;
int totalDivers = 0;
cout << "Welcome to diving Competition " << endl;
while (mainLoop == 'y')
{
DiverName.clear();
DiverCity.clear();
judge = 1;
loop = 1;
cout << " Please enter diver name: " << DiverName;
getline (cin, DiverName);
cout << "Please enter diver city: " << DiverCity;
getline (cin, DiverCity);
ScoreF:
cout<< " Enter score from judge #" << judge << ": ";
cin >> score;
if (score <= 0 || score > 10)
{
cout << "Please reenter (Valid Range: 0 - 10)" << endl;
goto ScoreF;
}
min = score;
max = score;
total = score;
do
{
judge++;
ScoreS:
cout << "Enter score from judge #" << judge << ": ";
cin >> score;
if (score <= 0 || score > 10)
{
cout << "Please reenter (Valid Range: 0 - 10)" << endl;
goto ScoreS;
}
if(score > max)
max = score;
if(score < min)
min = score;
total = score + total;
loop++;
}
while (loop < 5);
Difficulty:
cout << "Enter your difficulty: " << endl;
cin >> difficulty;
if (difficulty < 1 || difficulty > 1.67)
{
cout << "Please reenter (Valid Range: 1 - 1.67)" << endl;
goto Difficulty;
}
cout << " Diver: " << DiverName << " City: " << DiverCity << endl;
average = (total - (min + max)) / 3 * difficulty;
cout << setprecision(2) << fixed << "Overall score was " << average << endl;
totalDivers ++;
cout << "Number of divers participating: " << totalDivers << endl;
totalAverage += average;
overallAverage = (totalAverage / totalDivers);
cout << setprecision(2) << fixed << "Average score of all divers: " << overallAverage << endl;
cout << " Enter another diver?" << endl;
cout << "Press y to continue and n to exit" << endl;
cin >> mainLoop;
cin.ignore(50, ' ');
}
cout << " Event Summary " << endl;
cout << "Number of divers participating: " << totalDivers << endl;
overallAverage = (totalAverage / totalDivers);
cout << setprecision(2) << fixed << "Average score of all divers: " << overallAverage << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.