I'm having trouble with my assignment to make a program with a nested loop that averages out peoples score ignoring the highest and lowest scores then prompts the user to go back and enter another im fairly stuck atm here is what I have
#include <iostream>
using namespace std;
int main ()
{
cout << "Event: driving competition";
cout << "Please enter the driver's name;
int driverName;
cin >> driverName;
cout << "Please enter the driver's state;
int driverState;
cin >> driverState;
cout << "enter judge #1's score";
int judgeOne;
cin >> judgeOne;
if (judgeOne > 10)
cout << "Invalid number please reenter a number between 0 and 10";
return 9;
else
cout << "Please enter judge #2's score";
int judgeTwo;
cin >> judgeTwo;
if (judgeTwo > 10)
cout << "Invalid number please reenter a number between 0 and 10";
return 16;
else
cout << "Please enter judge #3's score";
int judgeThree;
cin >> judgeThree;
if (judgeThree > 10)
cout << "Invalid number please reenter a number between 0 and 10";
return 23;
else
cout << "Please enter judge #4's score";
int judgeFour;
cin >> judgeFour;
if (judgeFour > 10)
cout << "Invalid number please reenter a number between 0 and 10";
return 30;
else
cout << "Please enter judge #5's score";
int judgeFive;
cin >> judgeFive;
if (judgeFive > 10)
cout << "Invalid number please reenter a number between 0 and 10";
return 37;
else
cout << "Please enter the degree of difficulty";
int dDifficulty;
cin dDifficulty;
if (dDifficulty > 1.67,1.00>)
cout << " Invalid number answer must be between 1.00 and 1.67";
return 46;
Im aware some of it is incorrect and its unfinished the psuedocode for the assignment is
Input diver's name and city
Initialize highest score, lowest score and total score
Using a do-while loop input the 5 judge's scores
Validate the score to ensure it is between 0 and 10
Add score to total
Determine highest and lowest scores
Input and validate the degree of difficulty
Calculate the overall diver's score
Display the diver's information and overall score
Add diver's overall score to the final score
Add 1 to the number of divers
Prompt the user if she wants to process another diver
End-Loop
Calculate the average score for all divers
Display the number of divers and the average score for all divers
any help would be apriciated
int main ()
{
cout << "Event: driving competition\n""Please enter the driver's name";
int driverName; // Why int? Isn't this a string?
cin >> driverName;
cout << "Please enter the driver's state;
int driverState; // Why int? Isn't this a string?
cin >> driverState;
cout << "enter judge #1's score";
int judgeOne;
cin >> judgeOne;
// Some error here. I can enter < 0 still valid. Missing a OR statement?
if (judgeOne > 10)
cout << "Invalid number please reenter a number between 0 and 10";
// Why return? Return EXITS the function. In main thats the end of the program.
// return 9;
// An ODD else.
//else
cout << "Please enter judge #2's score";
int judgeTwo;
cin >> judgeTwo;
// Some error here. I can enter < 0 still valid. Missing a OR statement?
if (judgeTwo > 10)
cout << "Invalid number please reenter a number between 0 and 10";
// Why return? Return EXITS the function. In main thats the end of the program.
//return 16;
// An ODD else.
//else
cout << "Please enter judge #3's score";
int judgeThree;
cin >> judgeThree;
// Some error here. I can enter < 0 still valid. Missing a OR statement?
if (judgeThree > 10)
cout << "Invalid number please reenter a number between 0 and 10";
// Why return? Return EXITS the function. In main thats the end of the program.
//return 23;
// An ODD else.
//else
cout << "Please enter judge #4's score";
int judgeFour;
cin >> judgeFour;
// Some error here. I can enter < 0 still valid. Missing a OR statement?
if (judgeFour > 10)
cout << "Invalid number please reenter a number between 0 and 10";
// Why return? Return EXITS the function. In main thats the end of the program.
//return 30;
// An ODD else.
//else
cout << "Please enter judge #5's score";
int judgeFive;
cin >> judgeFive;
// Some error here. I can enter < 0 still valid. Missing a OR statement?
if (judgeFive > 10)
cout << "Invalid number please reenter a number between 0 and 10";
// Why return? Return EXITS the function. In main thats the end of the program.
//return 37;
// An ODD else.
//else
cout << "Please enter the degree of difficulty";
int dDifficulty; // Int? Don't you want a float/double?
cin dDifficulty; // Missing >>
if (dDifficulty > 1.67,1.00>)
cout << " Invalid number answer must be between 1.00 and 1.67";
// Why return? Return EXITS the function. In main thats the end of the program.
//return 46;
// Where you should return! It should return 0;
}
Logic Code for reading in scores and checking for correctness with loops:
#include <iostream>
int main()
{
// Very repeative data and questions.
// Use a simple loop, array, and functions to get valid input.
constint SIZE = 4; // Const Array Size.
int judge_score[SIZE]; // Array of scores
for (int i = 0; i < SIZE; ++i) // For loop
{
// i+1 so we get Judge 1-4 not 0-3 as text.
std::cout << "Enter judge " << i+1 << "'s Score (0-10):\n >";
// cin the data
std::cin >> judge_score[i];
while (judge_score[i] < 0 || judge_score[i] > 10) // Is it bad?
{
// Repeat with error until correct.
std::cout << "Please Enter a Score from 0 - 10:\n >";
std::cin >> judge_score[i];
}
}
}
Loops are relatively simple and you use them every day. When you wash your hair: Lather, Rinse, Repeat. Obviously you need to also have checks in the loop to know when to stop.
So if I was going to wash my hair:
1 2 3 4 5 6
while ( my_hair.is_dirty() ) // If it returns true
{
my_hair.shampoo();
my_hair.lather_shampoo();
my_hair.rinse_shampoo();
} // repeat
Now that's a real world example, but loops in code are good for incrementing through arrays, getting multiple cin values without writing cin over and over, and generally repeating code until an exit condition is met.