Hi everyone, I am very new to programming, and I am feeling stumped over a lab that we did in class last week. Here is a description of the problem and the pseudocode:
Problem:
Your State Dive Association presently scores its diving competitions with pencil and paper. They would like for you to design and develop a Dive Program in C++.
The paper forms that they presently use have the following:
Diver’s Name, City
JudgeScore1 - The scores entered are from 0 to 10.
JudgeScore2
JudgeScore3
JudgeScore4
JudgeScore5
DegreeOfDifficulty - This is assigned once for each diver.
OverAllScore - The overall score is the individual diver’s scores totaled and then divided by the degree of difficulty. The highest and lowest scores are removed as they are often skewed entries. Total the three scores left, divide them by 3, and then multiply that by the DegreeOfDifficulty. The degree of difficulty ranges from 1.00 to 1.67.
Display the diver's information and overall score.
When the competition is complete, there is a summary report created that lists the total number of divers and the average of the overall scores.
Pseudocode:
Write report heading
Loop as long as there are divers to process
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
I've attached the code that I came up with, though I feel like I might be missing the mark. I also keep getting several syntax errors when I try to build the solution:
1>------ Build started: Project: Lab 3, Configuration: Debug Win32 ------
1> Lab 3.cpp
lab 3.cpp(9): error C2059: syntax error : 'constant'
lab 3.cpp(47): error C2143: syntax error : missing ',' before ')'
lab 3.cpp(51): error C2143: syntax error : missing ';' before '{'
lab 3.cpp(56): error C2143: syntax error : missing ';' before '{'
lab 3.cpp(60): error C2143: syntax error : missing ';' before '{'
lab 3.cpp(62): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(62): error C2143: syntax error : missing ',' before ')'
lab 3.cpp(70): error C2143: syntax error : missing ';' before '{'
lab 3.cpp(75): error C2143: syntax error : missing ';' before '{'
lab 3.cpp(79): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(81): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(81): error C2143: syntax error : missing ',' before ')'
lab 3.cpp(89): error C2143: syntax error : missing ';' before '{'
lab 3.cpp(98): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(100): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(100): error C2143: syntax error : missing ',' before ')'
lab 3.cpp(108): error C2143: syntax error : missing ';' before '{'
lab 3.cpp(113): error C2143: syntax error : missing ';' before '{'
lab 3.cpp(117): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(119): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(119): error C2143: syntax error : missing ',' before ')'
lab 3.cpp(133): error C2143: syntax error : missing ';' before '{'
lab 3.cpp(137): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(149): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(159): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(160): error C2143: syntax error : missing ';' before '}'
lab 3.cpp(160): fatal error C1004: unexpected end-of-file found
If anybody has the time, can you please take a look at this and point me in the right direction? Any help is appreciated, I really don't want to fall behind 3 weeks into an 8 week course. Thanks!
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Declare variables
char continueLoop = 'Y', 'y';
string diverName, diverCity;
double highestScore = 0;
double lowestScore = 0;
double totalScore =0;
double overallScore = 0;
double diveDifficulty = 0;
double diverTotal = 0;
double avgScore = 0;
double score1, score2, score3, score4, score5 = 0;
int numberDivers = 0;
// Report heading
cout << " Report to the Media" << endl;
cout << " Event: Diving Competition" << endl;
// Attempt to design loops
while (continueLoop == 'Y' || continueLoop == 'y')
{
cout << "Enter the diver's name: ";
getline(cin, diverName);
cout << "Enter the diver's city: ";
getline(cin, diverCity);
// Input judge's scores
// Judge 1
do
{
int count = 0;
cout << "Enter the score from Judge #1: ";
cin >> score1;
while (score1 < 0 || score1 > 10)
{
cout << "Invalid score. Enter a new score (Score Range: 1 - 10)" << endl;
cout << "Enter the score from Judge #1: ";
cin >> score1;
}
count++;
} while (count < 1);
// Judge 2
do
{
int count = 0;
cout << "Enter the score from Judge #2: ";
cin >> score2;
while (score2 < 0 || score2 > 10)
{
cout << "Invalid score. Enter a new score (Score Range: 1 - 10)" << endl;
cout << "Enter the score from Judge #2: ";
cin >> score2;
}
count++;
} while (count < 1);
if (score2 < score1)
score2 = lowestScore;
if (score2 > score1)
score2 = highestScore;
// Judge 3
do
{
int count = 0;
cout << "Enter the score from Judge #3: ";
cin >> score3;
while (score3 < 0 || score3 > 10)
{
cout << "Invalid score. Enter a new score (Score Range: 1 - 10)" << endl;
cout << "Enter the score from Judge #3: ";
cin >> score3;
}
count++;
} while (count < 1);
if (score3 < lowestScore)
score3 = lowestScore;
if (score3 > highestScore)
score3 = highestScore;
//Judge 4
do
{
int count = 0;
cout << "Enter the score from Judge #4: ";
cin >> score4;
while (score4 < 0 || score4 > 10)
{
cout << "Invalid score. Enter a new score (Score Range: 1 - 10)" << endl;
cout << "Enter the score from Judge #4: ";
cin >> score4;
}
count++;
} while (count < 1);
if (score4 < lowestScore)
score4 = lowestScore;
if (score4 > highestScore)
score4 = highestScore;
// Judge 5
do
{
int count = 0;
cout << "Enter the score from Judge #5: ";
cin >> score5;
while (score5 < 0 || score5 > 10)
{
cout << "Invalid score. Enter a new score (Score Range: 1 - 10)" << endl;
cout << "Enter the score from Judge #5: ";
cin >> score5;
}
count++;
} while (count < 1);
if (score5 < lowestScore)
score5 = lowestScore;
if (score5 > highestScore)
score5 = highestScore;
diverTotal = (score1 + score2 + score3 + score4 + score5) - highestScore - lowestScore;
// Calculate degree of difficulty and overall diver's score
cout << "Enter the degree of difficulty (1 - 1.67): ";
cin >> diveDifficulty;
while (1 > diveDifficulty && diveDifficulty > 1.67)
{
cout << "Invalid degree of difficulty - Please reenter (Valid Range: 1 - 1.67)\n";
cout << "Please enter the degree of difficulty (1 - 1.67): ";
cin >> diveDifficulty;
}
overallScore = (diverTotal / 3) * diveDifficulty;
// Display diver's information and overall score
numberDivers++;
overallScore += totalScore;
cout << "Diver: " << diverName << endl;
cout << "City: " << diverCity << endl;
cout << "Overall Score: " << totalScore;
cout << "Would you like to enter another diver (Y/N)?";
cin >> continueLoop;
}
avgScore = totalScore / numberDivers;
// Output event summary
cout << " Event Summary" << endl;
cout << "Number of divers participating: " << numberDivers << endl;
cout << "Average score of all divers: " << avgScore << endl;
return 0;
}
|