C++ Console Application following the requirements below to allow entry of five
ID: 3869045 • Letter: C
Question
C++ Console Application following the requirements below to allow entry of five game scores for a bowler so that an average score can be calculated, high and low scores determined, with all results displayed.
Detailed requirements:
When the program starts the bowler is prompted for a score for ‘Game 1’.
Accept the bowling score from the user; valid bowling scores must be whole numbers between 0 and 300.
Use GetValidInteger() from MyInputValidation.h to accept and validate user input.
Once the entered score passes all validation, store the score in the relevant index of an array large enough to hold
the five scores to be entered.
The steps outlined above will all have to repeat (iterative structure required) to allow the entry of good scores for
five games. Refer to the sample output on the next page to help guide you in your planning.
For the purpose of this lab you must process your average score, and high/low scores at the time of each input.
Ensure that the average is eventually rounded to the nearest whole number.
NOTE: For this lab you may not use any of the sorting or searching functions to obtain the average, high or low You are required to write selection/iteration logic specific to the requirements of this lab.
After input, clear the screen and then produce output to match the screenshots supplied.
Display the original scores as shown followed by the player average, high score, and low score.
Display a prompt to the user asking if they would like to process another bowler’s scores for average calculation
and high/low determination. If the user elects to enter another bowler’s scores, clear the screen and repeat the entire process again beginning with a prompt to enter a score for Game 1; otherwise end the application with no further notification.
Please enter score for Game 1: 125 Please enter score for Game 2 400 Invalid input. Please try again and enter a value between and 300 300 Please enter score for Game 3 256 lease enter score for Game 4Bob for Game 4: Bob Invalid input. Please try again and enter a numeric value 100 Please enter score for Game 5: 218Explanation / Answer
NOTE: I have completed code for your assignment. please check and let me know if you face any issues. I will revert back within 24 hours.
Code:
#include <iostream>
#include <locale>
using namespace std;
// function prototype
int GetValidInteger(int);
int main()
{
int score_arr[5], high, low, score;
double total_score = 0;
char choice;
high = low = -1;
while(1){
for(int i = 0; i < 5; i++){
cout << "Please enter score for Game " << i+1 << ": ";
cin >> score;
score = GetValidInteger(score);
if (high == -1 && low == -1){
high = low = score;
score_arr[i] = score;
total_score += score;
continue;
}
if(score > high)
high = score;
if(score < low)
low = score;
score_arr[i] = score;
total_score += score;
}
cout << " Bowler Scores";
cout << " ================================================================= ";
for(int i = 0; i < 5; i++)
cout << " Game "<< i+1 <<": "<<score_arr[i];
cout << " =================================================================";
cout << " Average Score for Bowler: " << total_score/5 << endl;
cout << " High Score for Bowler: " << high << endl;
cout << " Low Score for Bowler: " << low << endl;
cout << " Would you like to process another set of bowler scores?" << endl;
cout << " Please enter 'Y' to continue or 'N' to exit: ";
cin >> choice;
choice = tolower(choice);
if(choice == 'n')
break;
else if(choice == 'y')
continue;
else
cout << " Invalid input, please try agin";
}
return 0;
}
int GetValidInteger(int score)
{
if(score > 0 && score <= 300)
return score;
while(1){
if(score < 0 || score > 300){
cout <<" Invalid input. Please try again and enter a value between 0 and 300. ";
cin >> score;
}
if(cin.fail()){
cout <<" Invalid input. Please try again and enter a numeric value. ";
cin.clear();
cin.ignore(256,' ');
cin >> score;
}
if(score > 0 && score <= 300)
break;
}
return score;
}
Code output screenshot:
https://pasteboard.co/GDgXr43.png
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.