``````#include<iostream>
using namespace std;

int main()
{

int x, s, g,;
int m[10];
cout<<"Input 10 numbers: "<<endl;
cout<<"number: ";
for(s=0; s<10; s++)
{

cin >>g;
m[s]=g;
}
cout<<"\n";

int max, max2;
max=max2=0;
for(int i=0; i<10; i++)
{
if(m[i]>max)
{
max2=max;
max=m[i];
}
if(m[i]>max2 && m[i]<max)
{
max2=m[i];
}
}
int low, low2=0;
for(int i=0; i<10; i++)
{
if(m[i]<low)
{
low2=low;
low=m[i];
}
else if(m[i]<low2)
{
low2=m[i];
}
}
cout<<"The largest value is: "<<max<<endl;
cout<<"The lowest value is : "<<low<<endl;
cout<<"The second largest value is: "<<max2<<endl;
cout<<"The second lowest value is : "<<low2<<endl;

system("PAUSE");
return 0;
}
#include<iostream>
using namespace std;

int main()
{

int x, s, g,;
int m[10];
cout<<"Input 10 numbers: "<<endl;
cout<<"number: ";
for(s=0; s<10; s++)
{

cin >>g;
m[s]=g;
}
cout<<"\n";

int max, max2;
max=max2=0;
for(int i=0; i<10; i++)
{
if(m[i]>max)
{
max2=max;
max=m[i];
}
if(m[i]>max2 && m[i]<max)
{
max2=m[i];
}
}
int low, low2=0;
for(int i=0; i<10; i++)
{
if(m[i]<low)
{
low2=low;
low=m[i];
}
else if(m[i]<low2)
{
low2=m[i];
}
}
cout<<"The largest value is: "<<max<<endl;
cout<<"The lowest value is : "<<low<<endl;
cout<<"The second largest value is: "<<max2<<endl;
cout<<"The second lowest value is : "<<low2<<endl;

system("PAUSE");
return 0;
}``````

so, is there something wrong with this?
when I run it and enter 1 2 3 4 5 6 7 8 9 0, it outputs correctly.

but when i enter 22 13 8 59 35 63 38 18 13 22
the output would be

The largest value is: 63
The lowest value is: 8
The second largest value is: 59
The second lowest value is:10

where did 10 come from? :ooh:

Initialise low1 and low2 to a high value. Check this

I just had them as 9999(all other numbers in the list were lesser than that.) and it works fine.

Here is the working code:

PS: Kindly format code the next time you post. It will be easier to read. :)

commented: Do NOT give working code. That's called cheating. -4

Initialise low1 and low2 to a high value. Check this

I just had them as 9999(all other numbers in the list were lesser than that.) and it works fine.

Here is the working code:

PS: Kindly format code the next time you post. It will be easier to read. :)

THANK YOU!!:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.