User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,760 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2810 | Replies: 7
Reply
Join Date: Dec 2007
Posts: 5
Reputation: finalheavenx is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
finalheavenx finalheavenx is offline Offline
Newbie Poster

Help how to find highest and lowest number..

  #1  
Dec 4th, 2007
please help me how to get the highest and lowest number when I input 10 numbers..

the first run is:
Enter First Number:
Enter Second Number:
Enter Third Number:
Enter Fourth Number:
Enter Fifth Number:
Enter Sixth Number:
Enter Seventh Number:
Enter Eighth Number:
Enter Ninth Number:
Enter Tenth Number:

Upon Finishing Input of 10 Numbers this is the output:

The Highest Number is: (highest number)
The Lowest Number is: (lowest number)

help me code this help will be appreciated.. thanks.. help me pls.. ^_^
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Posts: 2,779
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 15
Solved Threads: 229
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: how to find highest and lowest number..

  #2  
Dec 4th, 2007
Look at each number and save the highest number entered.

Did you miss reading the Rules?
Age is unimportant -- except in cheese
Reply With Quote  
Join Date: Mar 2005
Location: Phnom Penh, Cambodia
Posts: 415
Reputation: invisal will become famous soon enough invisal will become famous soon enough 
Rep Power: 5
Solved Threads: 36
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: how to find highest and lowest number..

  #3  
Dec 4th, 2007
First of all, I would have 2 variables; first one for storing Min, and the second one for shoring Max. While you input a number, you compare with the Min and Max. If that number is smaller than Min, then assign it to Min. If it is bigger than Max, then assign it to Max.
Reply With Quote  
Join Date: Jun 2007
Location: Home
Posts: 2,451
Reputation: zandiago is on a distinguished road 
Rep Power: 6
Solved Threads: 24
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: how to find highest and lowest number..

  #4  
Dec 4th, 2007
Maybe this will give you an idea:
http://www.daniweb.com/forums/showth...min+max+number
I shot the sheriff....but I didn't shoot the deputy
Reply With Quote  
Join Date: Dec 2007
Posts: 5
Reputation: sonsofliberty84 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sonsofliberty84 sonsofliberty84 is offline Offline
Newbie Poster

Re: how to find highest and lowest number..

  #5  
Dec 5th, 2007
what you could do is save each number into a file, then read that file line by line into a bubble sorter. Then when the program is done the first value in the file would be your highest number and the last number would be your lowest number.
Reply With Quote  
Join Date: Mar 2005
Location: Phnom Penh, Cambodia
Posts: 415
Reputation: invisal will become famous soon enough invisal will become famous soon enough 
Rep Power: 5
Solved Threads: 36
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: how to find highest and lowest number..

  #6  
Dec 5th, 2007
Originally Posted by sonsofliberty84 View Post
what you could do is save each number into a file, then read that file line by line into a bubble sorter. Then when the program is done the first value in the file would be your highest number and the last number would be your lowest number.

Why would you need to write it into file, when you can solve that problem without using saving into file.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote  
Join Date: Dec 2007
Posts: 5
Reputation: sonsofliberty84 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sonsofliberty84 sonsofliberty84 is offline Offline
Newbie Poster

Re: how to find highest and lowest number..

  #7  
Dec 5th, 2007
i guess all you need is to place each input in an array and then do a bubble sort on that array, then output the first and last values.
Reply With Quote  
Join Date: Mar 2005
Location: Phnom Penh, Cambodia
Posts: 415
Reputation: invisal will become famous soon enough invisal will become famous soon enough 
Rep Power: 5
Solved Threads: 36
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: how to find highest and lowest number..

  #8  
Dec 5th, 2007
Originally Posted by sonsofliberty84 View Post
i guess all you need is to place each input in an array and then do a bubble sort on that array, then output the first and last values.

Why don't you just compare it while you are inputting? Like this:

  1.  
  2. unsigned int n, min = 65535, max = 0, x;
  3. // How many number do you want to input?
  4. scanf("%d", &n);
  5.  
  6. for(int i = 0; i < n) {
  7. // Ask user to input their number
  8. printf("Please input your number: ");
  9. scanf("%d", &x);
  10.  
  11. if (min > x) min = x;
  12. if (max < x) max = x;
  13. }
  14.  
  15. // Out the final result
  16. printf("Max:%d\nMin:%d", max, min);
Last edited by invisal : Dec 5th, 2007 at 3:55 pm.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC