Need help understanding program

So I understand how this program is suppose to work; however, the commented part of "Notes" isn't clear for me. Under "test if new entry is now the largest," how do I record and remember the largest number entered by the user, and make it show the largest entered by the end?



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
   Demonstrate how to use an event-controlled loop to read
 input and find (remember) the largest value entered and
 number of values that were entered.

 NOTE: This program uses a constant defined in C++ called
 INT_MIN. This constant represents the smallest integer
 that C++ can handle. When we initialize the variable for
 the largest value to this it means any int read after that
 will be larger (by definition). Think about why this is
 necessary. What would happen if we initialize largest to 0
 and then the user enters a negative number. The 0 would be
 bigger, but the user never really entered a 0...

 */

#include<iostream>
using namespace std;

int main()
{
	char goAgain;					// variable to control event loop
	int latestInput;				// input values
	int largestSoFar = INT_MIN;		// variable to remember largest value
	int count = 0;					// variable to count loop iterations

	cout << "The program will remember the largest integer value entered.\n";

	// LOOP CONTROL: initialize loop event
	cout << "Would you like to begin (y or n): ";
	cin >> goAgain;
	cout << endl;

	// TODO, LOOP CONTROL: remove comment symbols on the while
	// line below and code the text expression between ( and ).

		while((goAgain == 'Y') || (goAgain == 'y'))
	{
		// TODO, LOOP PROCESS: prompt the user and get an input value
			cout << "\nEnter a whole number: ";
			cin >> latestInput;


		// TODO, LOOP PROCESS: test if new entry is now the largest seen
			

		// TODO, LOOP PROCESS: update iteration counter
			count++;



		// TODO, LOOP CONTROL: ask the user if they want to enter another and
		// read a new value into the loop control variable
			cout << "Enter another (Y or N): ";
			cin >> goAgain;


	}	// end of loop body

	// LOOP EXIT: display status of loop count and largest value
	cout << "You entered " << count << " values." << endl;

	if (count > 0)
		cout << "The largest value entered was " << largestSoFar << endl;

	cout << "\nEnd Program - ";

	return 0;
}

/* Sample Interaction and Output

Test #1:
=======================================================
The program will remember the largest integer value entered.
Would you like to begin (y or n): n

You entered 0 values.

End Program - Press any key to continue . . .

Test #2:
=======================================================
The program will remember the largest integer value entered.
Would you like to begin (y or n): Y

Enter a whole number: -19
Enter another (Y or N): y

Enter a whole number: 99
Enter another (Y or N): Y

Enter a whole number: 7
Enter another (Y or N): n

You entered 3 values.
The largest value entered was 99
 */
The variable largestSoFar is meant to contain the largest value you've seen so far. So each time the user enters a value, compare it to largestSoFar. If the value entered is bigger than largestSoFar, then assign that value to largestSoFar.
Topic archived. No new replies allowed.