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

double maxNumber( double inputNum,A double inputNumB)
{  double finalNum;
   if inputNumA > inputNumB {
   finalNum == inputNumA
   return inputNumA;
}}

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

Put your doubles into a vector, let's say dvector, and then use something like *max_element(dvector.begin(), dvector.end())

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??

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

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

This article has been dead for over six months. Start a new discussion instead.