loop assignment issues

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


Please edit your post and put the source inside code tags. It will make it a lot more legible and folks here will be more likely to look at it
What are you specifically stuck on?... Have you tried to compile your code as you make it to check for errors?

Oh, maybe edit the post and put the code tags to make everything all pretty. That would help to get more people to help you also.
code tags as in the // comments?
Lots of problems. Bad returns and else statements that print errors but do nothing in terms of corrections.
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
73
74
75
76
77
78
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

int main()
{
  // Very repeative data and questions.
  // Use a simple loop, array, and functions to get valid input.
  
  const int 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];
    }
  }
}
Last edited on
k thanks ill reread the chapter aswell loops just confuse me for some reason
[code][/code] <-- code tags


also on the right of where you type in the comment box when you post there are a bunch of "Format" buttons. It's in there also.
Last edited on
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.
wow, wolfgang... that my friend is a loop
We're all just loops.
also another thing that confused me was the phrasing for if a variable is between certain numbers for example if variable >10 but greater then 2
Topic archived. No new replies allowed.