following code is used to find the largest value for 10 number, using similar approach, find the find two largest values for 10 numbers. You may input each number only once..thanx ..
#include <iostream>
usingnamespace std;
int main()
{
int counter, number, largest;
counter = 1;
cout << "Enter a number: ";
cin >> largest;
while ( counter < 10 ) {
cout << "Enter next number: ";
cin >> number;
if ( number > largest )
largest = number;
counter++;
}
cout << "The largest no. is : " << largest << endl;
return 0;
}
I guess you need to modify your code in order to show the user not only the largest number, but also the "almost" largest... you could include an auxiliary vairiable, say second_largest and between lines 16 and 17 copy the "largest" into the "second_largest" before largest = number;