(I am a beginner, please don't be mean if I make any serious mistakes.) :sad:
The purpose of this program is to cout the largest and the second largest number among 10 numbers. Although I have thought for serveral times, I still don't get what is the problem.
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int counter=1;
int number;
int max;
int secondmax;
int few;//number of times the max. number appears
int secondfew;//number of times the second max. number appears
cout<<"Enter a number= ";
cin>>number;
max=number;
secondmax=number;
while(counter<10)
{
cout<<"Enter a number= ";
cin>>number;
if(number>max)
{
secondmax=max;
max=number;
few=1;
}
else if(number==max)
{
few++;
}
if(number>secondmax&&secondmax<max)
{
secondmax=number;
secondfew=1;
}
else if(number==secondmax&&secondmax<max)
{
secondfew++;
}
counter++;
}
cout<<"There are "<<few<<" person(s) with the maximum number of "<<max<<"."<<endl;
cout<<"There are "<<secondfew<<" person(s) with the second maximum number of "<<secondmax<<"."<<endl;
system("pause");
return 0;
}
If any of you know what is the problem, please give me a hand. Thank you very much.