(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
```

Computer Science & Information Technology

You might also like to view...

When designing your own on-screen form using the Form Wizard, first click the ____ tab.

A. CREATE B. HOME C. EXTERNAL DATA D. DATABASE TOOLS

Computer Science & Information Technology

What is an access technology?

What will be an ideal response?

Computer Science & Information Technology

When indexing an Access database, the Yes (No Duplicates) option builds an index so that every value in that field in the table is unique

Indicate whether the statement is true or false

Computer Science & Information Technology

List the types of models that might be used in requirements modeling and explain the role of each type of model

What will be an ideal response?

Computer Science & Information Technology