Loops

IDK why but am having a hard time getting these loops or understanding this assignment wanted to see if someone could possibly give me some direction. I am using visual studio 12 and C++ code. When i first completed the code I would get a @ symbol infinitely displayed on the screen so I made a change to a variable then it ask for diver and city then score but then would ask for inputs non stop and if i inputted a wrong value every input there after was invalid. So i changed the variables in my for loop and it now excepts the name and city as well as input then does nothing.

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
// ---------------------------------------------------------------
// Programming Assignment:	LAB 03
// Developer:			Jocko Davis
// Date Written:		03/26/2014
// Purpose:				Dive Score Calculator
// ---------------------------------------------------------------

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	//initialize variables
	string name = "";
	string city = "";
	char anotherDiver = 'y';
	int judgesScore = 0;
	int judgeCounter = 0;
	double highScore = 10;
	double lowScore = 0;
	double overallScore = 0;
	double totalOverallScore = 0;
	double totalScore = 0;
	double score = 0;
	double difficultyLevel = 0;
	double averageScore = 0;

	// get name and city
	cout << "Enter divers name: ";
	getline(cin, name);
	cout << "Enter divers city: ";
	getline(cin, city);
	cout << "Enter divers score between 0 and 10 ";
	cin >> judgesScore;

	for (int judgeScore = 0; judgeScore < 10; judgeScore++)
	{
		//check if score is highest
		if (judgesScore > highScore)
			highScore = judgesScore;
		// check if score is lowest
		if (judgesScore < highScore)
			highScore = judgesScore;
		score += judgesScore;

	while ( anotherDiver == 'y' || anotherDiver == 'Y')
	{
		

		// validate score range
		while(judgesScore < 0 || judgesScore > 10)
		{
			
			cout << "Your score is not in range." << endl;
			cout << "Enter score between 0 and 10 : ";
			cin >> score;
		}

	}
			// validate difficulty
			cout << "Input the Divers Dificulty level: ";
			cin >> difficultyLevel;
			while(difficultyLevel < 1 || difficultyLevel > 1.67)
			{
				cout << "Your difficulty score not in range. " << endl;
				cout << " Enter score between 1 and 1.67: ";
				cin >> difficultyLevel;
			}
			
			// calculate overall score
			score = score - highScore - lowScore / 3;
			overallScore = score * difficultyLevel;

			cout << " Diver: " << name << endl;
			cout << " City: " << city << endl;
			cout << " Overall Score: " << overallScore << endl;
			overallScore += totalOverallScore;
			judgeCounter++;

			score += judgesScore;
			cout << "Would you like to enter another Diver? ";
			cin >> anotherDiver;
			cin.ignore();
	}
			//average score
			averageScore = totalOverallScore / judgeCounter;
			cout << "Number of divers: " << judgeCounter << endl;
			cout << " Average Score: " << averageScore << endl;

			return 0;


}
closed account (EwCjE3v7)
Line 41 to 46 do the same thing, why not take the ifs away and write the statement?
The assignment state's to run the variable check as if statements so not sure why but that does make sense to just write those statements.
or should each statement be under one if statement???
You have a lot of score related variables. I'm trying to figure out what the program is trying to do. How is the scoring supposed to work for each diver?


Do you mean to set lowScore = judgesScore in the second part here?

1
2
3
4
5
if (judgesScore > highScore)
highScore = judgesScore;
// check if score is lowest
if (judgesScore < highScore)
highScore = judgesScore; 

Last edited on
Sorry this is all new to me and a new venture I have recently started to embark on because it fascinates me but I am essentially suppose to make a program to input diver's name and city as well as dive score. Here is the pseudocode file we where told to follow might give a better understanding than i have given but i greatly appreciate your help not sure why but my institute does not offer programming tutors.

iLab 3 enhanced 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
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
Input and validate the degree of difficulty
Ask the user to input the degree of difficulty
Use a while loop to make sure that the degree of difficulty is in the proper range
Calculate the overall diver's score
Subtract the high and the low from the score and divide by three
Multiply score by degree of difficulty and assign to overalscore
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
Call cin.ignore();
End-Loop
Calculate the average score for all divers
Divide the final score by the number of divers
Display the number of divers and the average score for all divers
Does anyone have any recommendations at all or a direction to point me????
This is my initial pseudo-code reading of the steps outlined there. Hopefully I read all of that right and this helps a little bit.

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
//general info - constant numbers
lowestscore = 0
highestscore = 10
lowestdifficulty = 1.00
highestdifficulty = 1.67

//diver specific info
divername
divercity
diverscore
divertotalscore
diverhighscore
diverlowscore
diverdifficulty
diveroverallscore

//counter controls
divercount=0
judgecount=0

//input control
repeat = false

//overall info
finalscore = 0.0
finalaverage = 0.0

do 
	Input diver name and city
	Initialize divertotalscore, diverhighscore to 0, diverlowscore to 10
	do  // loop through 5 judges for a diver
		input diverscore
		while (!(score >= lowestscore && score <=highestscore))
			"Invalid score entered"
			input diverscore
		divertotalscore+=diverscore
		if diverscore > diverhighscore, diverhighscore == diverscore
		if diverscore < diverlowscore, diverlowscore == diverscore
		judgecount++	
	while(judgecount<5)

	input diverdifficulty
	while (!(diverdifficulty >= lowestdifficulty && diverdifficulty <=highestdifficulty))
		"Invalid Diver difficulty entered"
		input diverdifficulty

	diveroverallscore = ((divertotalscore - diverhighscore - diverlowscore)/3) * diverdifficulty
	
	"Diver name: " divername "Diver City: " divercity "Diver Overall Score" diveroverallscore
	finalscore+=diveroverallscore
	divercount++

	"Enter another diver?" (If yes, repeat = true)
while (repeat)

finalaverage = finalscore / divercount
"Number of divers: " divercount "Average score" finalaverage
Last edited on
just a little more research and thought process i think i might have figure it out i essentially was running each loop separate instead of one nested loop so it was throwing everything off. will update if it officially works after i rewrite the code
Topic archived. No new replies allowed.