Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,735 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,345 people online right now. Registration is fast and FREE... Join Now!




find the highest and lowest of 3 intergers

 
Reply to this topicStart new topic

find the highest and lowest of 3 intergers, i'm tring to write a program that finds the smallest and largest o

fire21
4 Feb, 2007 - 11:39 PM
Post #1

New D.I.C Head
*

Joined: 4 Feb, 2007
Posts: 7


My Contributions
..........
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: 4 Feb, 2007 - 11:41 PM
User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Find The Highest And Lowest Of 3 Intergers
5 Feb, 2007 - 12:10 AM
Post #2

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,153



Thanked: 44 times
Dream Kudos: 125
My Contributions
I am not sure about what are you trying to do in your code but This is something I would have done...

CODE


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.
smile.gif
User is offlineProfile CardPM
+Quote Post

Louisda16th
RE: Find The Highest And Lowest Of 3 Intergers
5 Feb, 2007 - 12:10 AM
Post #3

 101010101
Group Icon

Joined: 3 Aug, 2006
Posts: 1,812



Thanked: 1 times
Dream Kudos: 755
My Contributions
I guess your having more of a logical error here. Your compiler will detect mainly syntax errors. Try this:
CODE

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.
smile.gif

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

This post has been edited by Louisda16th: 5 Feb, 2007 - 07:52 AM
User is offlineProfile CardPM
+Quote Post

Lord Hadies
RE: Find The Highest And Lowest Of 3 Intergers
5 Feb, 2007 - 07:39 AM
Post #4

D.I.C Regular
***

Joined: 24 Nov, 2006
Posts: 307


My Contributions
why are you reading in least after the if statement???
but Louisda16th is right smile.gif and as he said using similar logic you'll get the program to be right
User is offlineProfile CardPM
+Quote Post

fire21
RE: Find The Highest And Lowest Of 3 Intergers
5 Feb, 2007 - 09:12 AM
Post #5

New D.I.C Head
*

Joined: 4 Feb, 2007
Posts: 7


My Contributions
Thank You guys- just wanted a nudge on it and i got figured out. rolleyes.gif music.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 05:23AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month