This is what I have, but I'm struggling to achieve a goal which I'll explain shortly. Here is the code
I can easily work out the largest number entered by the user, but now I'm stuck on working out the second largest. I've tried many things, but I cannot get my mind around the maths to get to the second largest. Any help would be appreciated.Code:// Practise Exercise
#include <iostream>
using namespace std;
int main()
{
int counter = 1;
int number;
int largest = 0;
int next_largest = 0;
while ( counter <= 10 )
{
cout << counter << ". Enter a number: ";
cin >> number;
// works out largest number entered by user
if ( largest < number )
largest = number;
++counter;
}
cout << "Largest number entered:\t" << largest << '\n'
<< "Second lagest number entered:\t" << next_largest << endl;
system( "pause" );
return 0;
}