#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

Recommended Answers

All 4 Replies

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

You tell me. Try it and report back.

#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.

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 =]

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.