#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int high=0;
int low=0;
int number;
cout<<"Enter in the number"<<endl;
cin>>number;
high=number;
low=number;
for (int count=0;count<4;count++)
{
cout<<"Enter in the number"<<endl;
cin>>number;
if(number>high)
high=number;
if(number<low)
low=number;
}
cout<<"\nThe highest number is:"<<high;
cout<<"\nThe lowest number is:"<<low;


getch();
}


i cant understand this code plz help me is iit right or not

#include <iostream.h>

#include <conio.h>
void main()
{
     clrscr();
     int high=0;
     int low=0;
     int number;
     cout<<"Enter in the number"<<endl;
     cin>>number;
     high=number;
    low=number;
    for (int count=0;count<4;count++)
    {
           cout<<"Enter in the number"<<endl;
            cin>>number;
           if(number>high)
          high=number;
          if(number<low)
         low=number;
       }
              cout<<"\nThe highest number is:"<<high;
             cout<<"\nThe lowest number is:"<<low;


         getch();
}

Added Code Tags

And firstly, arent' you wanting to find the highest and lowest values in an array? I do not see any array declarations in your code. What you're doing right now is entering numbers and checking if they're higher or lower than the previous number.

You can read up on arrays here.

Edited 7 Years Ago by Kontained: n/a

Try this function here for finding the highest value in an array:

double max(double const Tab[], int const size)
{
     double max = Tab[0];       

     for(int i = 0; i < size; i++) 
     {
          if(Tab[i] > max)
		  {
			max = Tab[i];
		  }
     }
     return max;                

}//max

You should be able to do the rest by yourself if you get this =]

Edited 7 Years Ago by kekz0r: n/a

This article has been dead for over six months. Start a new discussion instead.