Homework assignment [Help]

This is super beginner C++ class, using basic math and loops.

I'm having trouble having the code to only have the score to be 1-10
and provide an invalid cout statement
then have another case to create the case with 5 judges and then ask the user at the end if they want to use the program again

the program i have built is below

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
// variables used for program
int choice;
int NumOfGymnasts = 0;


string name;

//code to welcome the user to the generator
cout << "Welcome to the Gymnastics Copetition Score Results!" << endl;


do
{
// start asking how many judges for the competition
cout << "Please pick from the following...\n" << endl;
cout << "1. 3 Judges \n" << endl;
cout << "2. 5 Judges \n" << endl;
cout << "3. Quit" << endl;
cin >> choice;

switch (choice)

{

// choice for 3 judges
case 1:
//narrowing down how many competitors and start calculation for scores
cout << "How many gymnasts are in the competition. Between 1-20 competitors\n" << endl;
cin >> NumOfGymnasts;

//entering a limit for how many gymnast in competition
if (NumOfGymnasts >= 1 && NumOfGymnasts <= 20)

{

//once clarified, varifying name and scores for gymnast in competition
for (int j =0; j < NumOfGymnasts; j++)

{

//asking user for gymnast name
cout << "Enter the gymnast name here...\n" << endl;
getline(cin, name);
cin >> name;

//identifiers for scores for three judges
double FIRST_SCORE, SECOND_SCORE, THIRD_SCORE;
double AVERAGE_SCORE;

//asking user judges score
cout << "Please score between 1-10. \n" << endl;
cout << "Enter first judge's score here...\n" << endl;
cin >> FIRST_SCORE;
cout << "Enter second judge's score here...\n" << endl;
cin >> SECOND_SCORE;
cout <<"Enter third judge's score here...\n" << endl;
cin >> THIRD_SCORE;

//output and calculations to provide average score for contestant
AVERAGE_SCORE = FIRST_SCORE + SECOND_SCORE + THIRD_SCORE / 3 ;
cout << fixed << setprecision(2);
cout << "Average score for contestant" << name << "is" << AVERAGE_SCORE << endl;

//putting error code if invalid answer
if((double FIRST_SCORE + SECOND_SCORE + THIRD_SCORE >= 0 && score <= 10))

break;
}

else if( != >=1 && SCORE <= 10);
{

//entering statement for invalid input by user
cout << "Not a valid score. Please submit correct score here...\n" << endl;

}





return 0;
Please edit your post to include code tags.
https://www.cplusplus.com/articles/jEywvCM9/
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
// variables used for program
int choice;
int NumOfGymnasts = 0;


string name;

//code to welcome the user to the generator
cout << "Welcome to the Gymnastics Copetition Score Results!" << endl;


do
{
// start asking how many judges for the competition
cout << "Please pick from the following...\n" << endl;
cout << "1. 3 Judges \n" << endl;
cout << "2. 5 Judges \n" << endl;
cout << "3. Quit" << endl;
cin >> choice;

switch (choice)

{

// choice for 3 judges
case 1:
//narrowing down how many competitors and start calculation for scores
cout << "How many gymnasts are in the competition. Between 1-20 competitors\n" << endl;
cin >> NumOfGymnasts;

//entering a limit for how many gymnast in competition
if (NumOfGymnasts >= 1 && NumOfGymnasts <= 20)

{

//once clarified, varifying name and scores for gymnast in competition
for (int j =0; j < NumOfGymnasts; j++)

{

//asking user for gymnast name
cout << "Enter the gymnast name here...\n" << endl;
getline(cin, name);
cin >> name;

//identifiers for scores for three judges
double FIRST_SCORE, SECOND_SCORE, THIRD_SCORE;
double AVERAGE_SCORE;

//asking user judges score
cout << "Please score between 1-10. \n" << endl;
cout << "Enter first judge's score here...\n" << endl;
cin >> FIRST_SCORE;
cout << "Enter second judge's score here...\n" << endl;
cin >> SECOND_SCORE;
cout <<"Enter third judge's score here...\n" << endl;
cin >> THIRD_SCORE;

//output and calculations to provide average score for contestant
AVERAGE_SCORE = FIRST_SCORE + SECOND_SCORE + THIRD_SCORE / 3 ;
cout << fixed << setprecision(2);
cout << "Average score for contestant" << name << "is" << AVERAGE_SCORE << endl;

//putting error code if invalid answer
if((double FIRST_SCORE + SECOND_SCORE + THIRD_SCORE >= 0 && score <= 10))

break;
}

else if( != >=1 && SCORE <= 10);
{

//entering statement for invalid input by user
cout << "Not a valid score. Please submit correct score here...\n" << endl;

}





return 0;
maytambo,
1. Don't put semi-colons (;) after the if (condition). e.g. line 81.
2. division, /, has higher precedence than addition, +. Line 71 is not calculating your average correctly.
3.
1
2
getline(cin, name);
cin >> name;

Either use getline, or cin >>. Don't use both.
getline allows for whitespace to be used in the name.
4. double FIRST_SCORE + SECOND_SCORE + THIRD_SCORE >= 0
This syntax doesn't make sense.
Don't put double there.
5. f( != >=1 && SCORE <= 10)
This syntax doesn't make sense.
Last edited on
@maytambo, is that really ALL of your code? It is missing two closing brackets, and the two if statements are not valid statements.

The code as you show it will not compile.
Topic archived. No new replies allowed.