Hi, I am trying to find 2nd largest number that given input of numbers. The question is
actually consider that you enter 5 number : 60, 70, 30, 40, 55 randomly -the order does not matter- my function should find 2nd largest number and return it. I am trying but I did not manage to finish my code and actually I can not a way to find true algorithm for this question. The rule is -I know already how I can find max or min number in array, it is simple- you do not use any type of array / pointer / dynamic memory allocation
Here is my code in fact I couldn't write anything related to heart of this question :(
#include <iostream>
using namespace std;
int secondLargestNumber()
{
int nofStudent, grade;
int max;
int secondMax;
cout <<"Please enter the number of students that have taken this exam: "<<endl;
do
{
cin>>nofStudent;
if (nofStudent < 0 || nofStudent > 50)
{
cout<< "Please re-enter the class size!"<<endl;
}
}while (nofStudent < 0 || nofStudent > 50);
cout << "Now, we passed just do-while"<<endl;
cout<<"********************************"<<endl;
cout<< "Enter the grades of these students: "<<endl;
for (int i = 0; i < nofStudent; ++i)
{
cin>>grade;
while (grade > 100 || grade < 0)
{
cout<<"Please enter valid grades for each of these students: "<<endl;
cin>>grade;
}
}
/*
cout<<endl;
cout<<"Keep is : "<<keep<<endl;
cout<<endl;
cout<<"Grade is : "<<grade<<endl;
cout<<endl; */
cout<<"******************************"<<endl;
cout <<"Max : "<<&max<< " and 2. Max : " <<&secondMax<<endl<<grade<<endl;
return 6;
}
int main ()
{
cout<<endl;
cout<<"TYPE"<<endl;
cout<<endl;
secondLargestNumber();
return 0;
}
It is not my homework, it was our quiz question yesterday and I did not solve but I am curious on how to set up true thinking or algorithm, thanks...