•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,911 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,087 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: 451 | Replies: 5
![]() |
•
•
Join Date: Oct 2007
Posts: 49
Reputation:
Rep Power: 1
Solved Threads: 0
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
i know i need to used recursion function, but how should i declare the function??
here is what i have so far
c++ Syntax (Toggle Plain Text)
double maxNumber( double inputNum,A double inputNumB) { double finalNum; if inputNumA > inputNumB { finalNum == inputNumA return inputNumA; }}
Last edited by Ancient Dragon : Nov 25th, 2007 at 9:37 am. Reason: corrected code tags
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
- storing a variable number of values in a vector
- scanning that vector for the largest value, using a for loop
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
> 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.
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,840
Reputation:
Rep Power: 11
Solved Threads: 189
> 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?
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.
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
Hope this helps.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Need help writing a function (Visual Basic 4 / 5 / 6)
- Need help writing this function (C)
- Pointer and function (C++)
- Lisp help - is this function right? (Legacy and Other Languages)
- writing method (Java)
- traverse function doubly linked list (C)
- Stuck writing a Function (C++)
- writing an array to a file (C++)
Other Threads in the C++ Forum
- Previous Thread: please send answer until 26.11.2007
- Next Thread: Arrays



Linear Mode