(Find the Two Largest Numbers) Using an approach similar to that in Exercise 3.17, find the two largest values among the 10 numbers. [Note: You must input each number only once.]
What will be an ideal response?
```
// Find the two largest numbers.
#include
using namespace std;
int main()
{
int counter = 0; // counter for 10 repetitions
int number; // current number input
int largest; // largest number found
int secondLargest; // second-largest number found
cout << "Enter the first number: "; // prompt for first number
cin >> largest; // get first number
cout << "Enter next number: "; // prompt for second number
cin >> number; // get second number
// compare second number with first number
if ( number > largest )
{
secondLargest = largest;
largest = number;
} // end if
else
secondLargest = number;
counter = 2; // set counter
// get rest of the numbers and find the largest and secondLargest
while ( counter < 10 )
{
cout << "Enter next number: "; // prompt for next number
cin >> number; // get next number
// compare current number with largest and secondLargest
if ( number > largest )
{
secondLargest = largest;
largest = number;
} // end if
else if ( number > secondLargest )
secondLargest = number;
counter++; // increment counter
} // end while
// display largest two numbers
cout << "\nLargest is " << largest
<< "\nSecond largest is " << secondLargest << endl;
} // end main
```
You might also like to view...
When the mouse pointer points to an icon, which of the following displays and provides information about the icon?
A) Notification area B) Taskbar C) ScreenTip D) Shortcut menu
Which of the following represents the definition of information compliance?
A. The act of conforming, acquiescing, or yielding information B. The ability to comply with software C. The understanding of technology D. The verbalization of information governance in a company's policies and procedures.