find the highest and lowest of 3 intergers

i'm tring to write a program that finds the smallest and largest o

Page 1 of 1

4 Replies - 20801 Views - Last Post: 05 February 2007 - 10:12 AM Rate Topic: -----

#1 fire21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-February 07

find the highest and lowest of 3 intergers

Post icon  Posted 05 February 2007 - 12:39 AM

..........
if (num1<=num2)
cin >> least;
cout << "Least Integer is: ";

if (num1<=num3)
cin >> least;
cout << "Least Integer is: ";

if (num2<=num3)
cin >> least;
cout << "Least Integer is: ";

if (num2<=num1)
cin >> least;
cout << "Least Integer is: ";

if (num3<=num1)
cin >> least;
cout << "Least Integer is: ";

if (num3<=num2)
cin >> least;
cout << "Least Integer is: ";


if (num1>=num2)
cin >> largest;
cout << "Largest Integer is: ";

if (num1>=num3)
cin >> largest;
cout << "Largest Integer is: ";

if (num2<=num3)
cin >> largest;
cout << "Largest Integer is: ";

if (num2<=num1)
cin >> largest;
cout << "Largest Integer is: ";

if (num3<=num1)
cin >> largest;
cout << "Largest Integer is: ";

if (num3<=num2)
cin >> largest;
cout << "Largest Integer is: ";

return 0;
}

i am trying to get the program to find the highest and lowest of the 3 numbers.. but when i run it its not doing so- i have 0 errors and 0 warnings

This post has been edited by fire21: 05 February 2007 - 12:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: find the highest and lowest of 3 intergers

#2 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 119
  • View blog
  • Posts: 1,565
  • Joined: 25-January 07

Re: find the highest and lowest of 3 intergers

Posted 05 February 2007 - 01:10 AM

I am not sure about what are you trying to do in your code but This is something I would have done...

cout<<"Enter Number 1 : ";
cin>>number1;
cout<<"Enter Number 2 : ";
cin>>number2;
cout<<"Enter Number 3 : ";
cin>>number3;

if(number1>=number2)
{
  if(number1>=number3)
  {
	cout<<"Largest Number Is : "<<number1;
	if(number2<=number3)
	  cout<<"Smallest Number Is : "<<number2;
	else
	  cout<<"Smallest Number Is : "<<number3;
  }
  else
  {
	cout<<"Largest Number Is : "<<number3;
	cout<<"Smallest Number Is : "<<number2;
  }
}
else
{
  if(number2>=number3)
  {
	cout<<"Largest Number Is : "<<number2;
	if(number1<=number3)
	  cout<<"Smallest Number Is : "<<number1;
	else
	  cout<<"Smallest Number Is : "<<number3;
  }
  else
  {
	cout<<"Largest Number Is : "<<number3;
	cout<<"Smallest Number Is : "<<number1;
  }
}





I hope this will help you.
:)
Was This Post Helpful? 0
  • +
  • -

#3 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: find the highest and lowest of 3 intergers

Posted 05 February 2007 - 01:10 AM

I guess your having more of a logical error here. Your compiler will detect mainly syntax errors. Try this:
if(num1<num2 && num1<num3)
{
	/*num1 is smallest*/
}


Hope you get it. Try the rest of it yourself. It should be easy. You'll need a few more similar 'if' statement blocks.
:)

EDIT: mmmm. I didn't realise this before. I was too slow for AmitTheInfinity. :D

This post has been edited by Louisda16th: 05 February 2007 - 08:52 AM

Was This Post Helpful? 0
  • +
  • -

#4 Lord Hadies  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 307
  • Joined: 24-November 06

Re: find the highest and lowest of 3 intergers

Posted 05 February 2007 - 08:39 AM

why are you reading in least after the if statement???
but Louisda16th is right :) and as he said using similar logic you'll get the program to be right
Was This Post Helpful? 0
  • +
  • -

#5 fire21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-February 07

Re: find the highest and lowest of 3 intergers

Post icon  Posted 05 February 2007 - 10:12 AM

Thank You guys- just wanted a nudge on it and i got figured out. :rolleyes: :music:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1