Question: C++- Please solve TODO sections and match sample output. Use a while to search data, looking for the largest entry Demonstrate how to use an

C++- Please solve TODO sections and match sample output.

Use a while to search data, looking for the largest entry

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

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. ";

// 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( /* replace with test expression */ )

{

// TODO, LOOP PROCESS: prompt the user and get an input value

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

// TODO, LOOP PROCESS: update iteration counter

// TODO, LOOP CONTROL: ask the user if they want to enter another and

// read a new value into the loop control variable

} // 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 << " End 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

End Program - Press any key to continue . . .

*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!