|
-
November 14th, 2011, 12:03 AM
#1
Need Help with loops and adding all scores
I need to add 5 judge scores and add them to total score but I have no idea to go about this. How would I go about using this psuedocode?
Using a do-while loop input the 5 judge's scores
Start do while ( or for loop) loop
Ask the user to input a judges score
Validate the score to ensure it is between 0 and 10
use a while loop to input another score if it is not between 0 and 10
Add score to total
Determine highest and lowest scores
If score is greater than highest assign score to highest
If score is less than lowest assign score to lowest
Increment the judgeCount variable
I tried this if loop and while loops but it isn't working. I'm not understanding how to add all 5 judge scores and setting the highest score to lowest. Here is my code.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void main()
{
string diverName, diverCity;
int judgeScore, judgeScore2, judgeScore3, judgeScore4, judgeScore5;
double totalScore;
double difficulty;
int highScore;
int lowScore;
cout << "Enter the Diver's name" << endl;
cin >> diverName;
cout << "Enter the Diver's city" << endl;
cin >> diverCity;
// 5 Judge Score inputs
for(int i = 0; i < 5; i++)
{
cout << "Enter the score given by judge # 1: ";
cin >> judgeScore;
cout << "Enter the score given by judge #2: ";
// Test input
while ( judgeScore < 0 || judgeScore > 10)
{
cout << "Invalid score - Please reenter (Valid Range: 0 - 10)" << endl;
cout << "Enter the score given by judge # 1: " << endl;
cin >> judgeScore;
}
}
cout << "What was the degree of difficulty?" << endl;
cin >> difficulty;
while(difficulty < 0 || difficulty > 1.67)
{
cout << "Invalid degree of difficulty, please reenter: " << endl;
}
totalScore = judgeScore / difficulty;
cout << "Diver Name: " << diverName << "City: " << diverCity;
cout << "The overall score was: " << totalScore << endl;
system("pause");
}
-
November 14th, 2011, 01:38 AM
#2
Re: Need Help with loops and adding all scores
1) Please use code tags when posting code. The code you posted is unformatted and almost unreadable without them.
2)
So where is this step in your code? Note the word "Add" is bolded. You do no addition at all in your code. The total should start at 0, and you add each score to this total.
3) The main() program returns int, not void.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|