### Second maximum value in while loop

So the question is to input prices of books using while loop and find out the maximum price,second maximum price,minimum price and total number of books with maximum and minimum price. I've successfully done most part of the program but having one issues with the second max price thing.
lets say we input price as:
9
8
7
6
5
then the second max price is given equal to maximum price.
Please keep it simple like it is as its the requirement.

[code]
#include <iostream>
using namespace std;
int main()
{
int price=0,max=0,tmax=0,smax,tsmax=0,min=9999,tmin=0,i=0,buff=0;
cout<<"enter price"<<endl;
cin>>price;
smax=price;
while(price!=-1)
{

i=i+1;
if(max<price)
{
smax=max;
max=price;
tmax=0;
}
if(max==price)
tmax++;
if(min>price)
{
min=price;
tmin=0;
}
if(min==price)
tmin++;
cin>>price;
}
cout<< "Total No of books" << i << endl;
cout << "MAX PRICE = " << max << "~" << tmax << endl;
cout << "SECOND MAX PRICE = " << smax << endl;
cout << "MIN PRICE = " << min << "~" << tmin << endl;
system ("pause");
return 0;
}

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````// So the question is to input prices of books using while loop and find out // the maximum price,second maximum price,minimum price and total number of // books with maximum and minimum price. I've successfully done most part of // the program but having one issues with the second max price thing. // lets say we input price as: // 9 // 8 // 7 // 6 // 5 // then the second max price is given equal to maximum price. // Please keep it simple like it is as its the requirement. #include using namespace std; int main() { int price=0,max=0,tmax=0,smax,tsmax=0,min=9999,tmin=0,i=0,buff=0; cout<<"enter price"<>price; // let's enter 9 8 7 6 5 -1 smax=price; // smax == 9; max == 0 while(price!=-1) { i=i+1; if(max block executed { smax=max; // smax == 0 --> this will never change max=price; tmax=0; } if(max==price) tmax++; if(min>price) { min=price; tmin=0; } if(min==price) tmin++; cin>>price; } cout<< "Total No of books" << i << endl; cout << "MAX PRICE = " << max << "~" << tmax << endl; cout << "SECOND MAX PRICE = " << smax << endl; cout << "MIN PRICE = " << min << "~" << tmin << endl; system ("pause"); return 0; }``````