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,968 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,746 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: 516 | Replies: 5
Reply
Join Date: Oct 2007
Posts: 49
Reputation: nicz888 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
nicz888 nicz888 is offline Offline
Light Poster

need help writing function

  #1  
Nov 24th, 2007
how would i write a maximum number test function that will take any number of arguments and returns the greatest of them???

i know i need to used recursion function, but how should i declare the function??

here is what i have so far

  1. double maxNumber( double inputNum,A double inputNumB)
  2. { double finalNum;
  3. if inputNumA > inputNumB {
  4. finalNum == inputNumA
  5. return inputNumA;
  6. }}
Last edited by Ancient Dragon : Nov 25th, 2007 at 10:37 am. Reason: corrected code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: need help writing function

  #2  
Nov 24th, 2007
So what's wrong with say
- storing a variable number of values in a vector
- scanning that vector for the largest value, using a for loop
Reply With Quote  
Join Date: Mar 2007
Posts: 1,449
Reputation: Lardmeister is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 8
Lardmeister's Avatar
Lardmeister Lardmeister is offline Offline
Nearly a Posting Virtuoso

Re: need help writing function

  #3  
Nov 24th, 2007
Put your doubles into a vector, let's say dvector, and then use something like *max_element(dvector.begin(), dvector.end())
I upped my sanitary measures, up yours!
Reply With Quote  
Join Date: Oct 2007
Posts: 49
Reputation: nicz888 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
nicz888 nicz888 is offline Offline
Light Poster

Re: need help writing function

  #4  
Nov 24th, 2007
what is dvector,
is there any other way of doing this function beside vector, i don't think we have covered that in my course yet??
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: need help writing function

  #5  
Nov 25th, 2007
> i don't think we have covered that in my course yet?
OK, so go with plain good old fashioned arrays then, and start with a small program which fills the array with some numbers input by the user.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: need help writing function

  #6  
Nov 25th, 2007
> how would i write a maximum number test function that will take any number of arguments and returns the greatest of them???

I think it would be very odd that your professor wants you to create a function that takes a variable number of arguments. Perhaps you should work with finding the largest number in an array?

Don't use recursion unless your professor explicitly asked you to. I don't imagine he did if you are to work with a variable number of numbers...

To figure out your problem, you have to think about how you, yourself can find the largest number in a list. For example, if I give you the following numbers, which is largest?
1295876
1279553
1295976
1297854
Figure out how you figure it out on your own, and then you can tell the computer how to figure it out. Make sense?

Hope this helps.
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:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC