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
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;
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdlib>
#include <ctime>
usingnamespace 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;
}
elseif( != >=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.