In c++, I have to write a code to get the user's desired numbers in each line with "while" command and when the user enter number -1 at the end, I have to display the largest number, the largest number other than the previous number, and the number of row with the largest number entered. For example user's numbers is:
4
7
11
5
-1
and result is:
11(the biggest number)
7(the biggest number after 11)
3(the row that the user has entered the largest number)
This is my own code:
#include <iostream>
using namespace std;
int main()
{
int price;
int max=0;
cin>>price;
while(price!=-1)
{
while(price>max)
{
max=price;
}
cin>>price;
}
cout<<max;
return 0;
}
I can find the largest number, but not the other two variables.