-1

#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

5
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by kekz0r
0

#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 by Kontained: n/a

0

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 by kekz0r: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.