Original Post
NOTICE: I typed my topic wrong, I'm trying to find the 2 highest numbers of 10 numbers. Hello, I'm doing an exercise in a book and I'm currently trying to make a program using a while loop to find the two highest numbers of 10 numbers. I can make it find the highest number, but I don't know how to make it find the second highest. Also, in the book it has a hint that says "You must input each number only once." The part where I'm stuck is the fact that I have no Idea how to make it check to see if it is not greater than the largest but also greater than the second largest.
int main()
{
int counter; // control loop
int number; // number of items sold
int largest; // largest number
int secondLargest; // second largest number
// pre-processing stage
counter = 1;
largest = 0;
secondLargest = 0;
// processing stage
while ( counter <= 10 )
{
cout << "Enter quantity sold: ";
cin >> number;
if ( number > largest )
largest = number;
// This is where i'm stuck
if ( largest != number )
secondLargest = number;
counter++; // increment counter by 1
}
// termination phase
cout << "The largest number is " << largest << endl;
cout << "The second largest number is " << secondLargest
<< endl;
system( "pause" );
return 0;
}