I can't get my second diver to appear

Doing a midterm assignment, and it is almost complete. The program is supposed to grade divers and give them a rating. You give the name and city of each diver, then the judges scores are given. This continues until you no longer want to include any more divers. The highest and lowest grades are supposed to be removed and then a average is taken. This average is supposed to be multiplied by a degree of difficulty. All of this works fine, but then when I try to enter a second diver it wont ask for a name, and I do not know why.
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
  #include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
	cout << "**************REPORT TO THE MEDIA***************" << endl;
	cout << endl;
	cout << "--------------DIVING COMPETITION----------------" << endl;
	cout << endl;

	// declare variable
	double score;
	double highScore = 0;
	double lowScore = 10;

	double diff;
	double totalScore = 0;
	double scoreFinal;
	double result;
	string diverName;
	string city;
	char ans = 'y';
	int totalDiver = 0;
	double totalresult = 0;


	while (ans == 'y' || ans == 'Y')
	{
		//input and  validate diver name
		cout << "Enter the diver's name: ";
		getline(cin, diverName);
		cout << "Enter the diver's city: ";
		getline(cin, city);

		double sumScore = 0; // assign sumScore 

		// input, validate input score
		for (int i = 0; i < 5; i++)
		{
			cout << "Enter the score for judge #" << i + 1 << ": ";
			cin >> score;
			while (cin.fail() || (score < 0) || (score > 10))
			{
				if (cin.fail())
					cout << "It can not be a letter. Try agian: ";
				else
					cout << "Valid score is from 0 to 10. Try agian: ";

				cin.clear();
				cin.ignore(10, '\n');
				cin >> score;

			}

			sumScore = sumScore + score;// sum total score

			// find lowest and highest score
			if (score >= highScore)
				highScore = score;
			if (score <= lowScore)
				lowScore = score;

		}

		// input and validate difficulty
		cout << "What was the degree of difficulty? ";
		cin >> diff;
		while (cin.fail() || (diff < 1) || (diff > 1.8))
		{
			if (cin.fail())
				cout << "It must be a number. Try agian:";
			else
				cout << "Valid number is from 1 to 1.8: ";

			cin.clear();
			cin.ignore(10, '\n');
			cin >> diff;
		}

		// calculation to remove the highest score and lowest score then multiply the result to difficulty
		scoreFinal = (sumScore - highScore - lowScore) / 3;
		result = scoreFinal *diff;


		// out put the result
		cout << "----------------------------------------";
		cout << endl;
		cout << "Diver: " << diverName << ", " << city << endl;
		cout << "Overal score is " << fixed << setprecision(1) << result << endl;
		cout << endl;

		// propt the user if he/she wants to get the result for another diver
		cout << "Do you want to process another diver (Y/N)? ";
		cin >> ans;
		cout << endl;


		// find the number of divers and total score of all users
		totalDiver = totalDiver + 1;
		totalresult = totalresult + result;

	}

	// calculate the average score and out put the even summary
	double evenResult = totalresult / totalDiver;
	cout << endl;
	cout << "------------EVENT SUMMARY---------------" << endl;
	cout << endl;
	cout << "Number of divers participating: " << totalDiver << endl;
	cout << "Average score of all divers: " << fixed << setprecision(1) << evenResult << endl;
	cout << endl;

	system("pause");
	return 0;
}







Try using a do-while instead of a while loop and remove the initialization for ans
What would I use to have the user answer the question?
Try replacing line 32 with getline(cin >> std::skipws, diverName);

"cin >> ..." is leaving a carriage return ('\n') in the input buffer. When you loop around and getline is getting ready to read in a name, it sees the carriage return and says, "Looks like I've hit the end of the line. All done getting input."

What std::skipws does is format the input stream to skip all leading whitespace, including the newline that was left in the input buffer.
Remove the initialization, not the declaration.
Okay I removed the initialization, but I am still running into the same problem. I also tried to make that modification to line 32 with no change.
This is the updated code that I tried.
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
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
	cout << "**************REPORT TO THE MEDIA***************" << endl;
	cout << endl;
	cout << "--------------DIVING COMPETITION----------------" << endl;
	cout << endl;

	// declare variable
	double score; 
	double highScore = 0;
	double lowScore = 10;
	
	double diff;
	double totalScore = 0;
	double scoreFinal;
	double result;
	string diverName;
	string city;
	char ans;
	int totalDiver = 0;
	double totalresult = 0;

	
	do
	{ 
		//input and  validate diver name
		cout << "Enter the diver's name: ";
		getline(cin >> std::skipws, diverName);
		cout << "Enter the diver's city: ";
		getline(cin, city);

		double sumScore = 0; // assign sumScore 

		// input, validate input score
		for (int i = 0; i < 5; i++)
		{
			cout << "Enter the score for judge #" << i + 1 << ": ";
			cin >> score;
			while (cin.fail() || (score < 0) || (score > 10))
			{
				if (cin.fail())
					cout << "It can not be a letter. Try agian: ";
				else
					cout << "Valid score is from 0 to 10. Try agian: ";

				cin.clear();
				cin.ignore(10, '\n');
				cin >> score;

			}

			sumScore = sumScore + score;// sum total score

			// find lowest and highest score
			if (score >= highScore)
				highScore = score;
			if (score <= lowScore)
				lowScore = score;

		}

		// input and validate difficulty
		cout << "What was the degree of difficulty? ";
		cin >> diff;
		while (cin.fail() || (diff < 1) || (diff > 1.8))
		{
			if (cin.fail())
				cout << "It must be a number. Try agian:";				
			else
				cout << "Valid number is from 1 to 1.8: ";

			cin.clear();
			cin.ignore(10, '\n');
			cin >> diff;
		}

		// calculation to remove the highest score and lowest score then multiply the result to difficulty
		scoreFinal = (sumScore - highScore - lowScore) / 3;
		result = scoreFinal *diff;


		// out put the result
		cout << "----------------------------------------";
		cout << endl;
		cout << "Driver: " << diverName << ", " << city << endl;
		cout << "Overal score is " << fixed << setprecision(1) << result << endl;
		cout << endl;

		// propt the user if he/she wants to get the result for another diver
		cout << "Do you want to process another diver (Y/N)? ";
		cin >> ans;
		cout << endl;
		

		// find the number of divers and total score of all users
		totalDiver = totalDiver + 1;
		totalresult = totalresult + result;

	} while (ans == 'y' || ans == 'Y');

	// calculate the average score and out put the even summary
	double evenResult = totalresult / totalDiver;
	cout << endl;
	cout << "------------EVENT SUMMARY---------------" << endl;
	cout << endl;
	cout << "Number of divers participating: " << totalDiver << endl;
	cout << "Average score of all divers: " << fixed << setprecision(1) << evenResult << endl;
	cout << endl;

	system("pause");
	return 0;
}






I also don't know how validate the yes no at the end of the program.
Topic archived. No new replies allowed.