How to find a maximum of entered numbers?

Posted 23 December 2010 - 11:35 AM

My goal is that the program asks floating-point numbers until the user enters 0 or negative number and then it has to find the maximum value of those and print the maximum to the screen. I've come up with this solution, but it is not entirely correct. Can someone help me with this problem? Thanks!

Re: How to find a maximum of entered numbers?

I would suggest setting the numbers up in an array so it is easier to deal with.

But if you want to do it your way try this::

if(n>m){
m = n;
}

Now what that did, was make it so if the value in n is greater than m( which is 1), it will make that value m. So say n is 2. 2 is greater than m, now m = 2. It goes back through say with the number 5. 5 is greater and 2, therefore making m 5.

Re: How to find a maximum of entered numbers?

Posted 24 December 2010 - 12:54 AM

My question wasn't about the deklaration, it was about the codes loop, why couldn't you just answer the question. And by the way thanks for -1, the reputation was indeed to high. What a great way for the moderator to greet a rookie programmer, who is looking for help.

Re: How to find a maximum of entered numbers?

Posted 24 December 2010 - 07:12 AM

progc, on 23 December 2010 - 11:54 PM, said:

My question wasn't about the deklaration, it was about the codes loop, why couldn't you just answer the question. And by the way thanks for -1, the reputation was indeed to high. What a great way for the moderator to greet a rookie programmer, who is looking for help.

Yes, and you're treating him so much better.

Your specific question may not have been about the function declaration, but JackOfAllTrades was trying to tell you how to format your function in a way that is standard so that it will be more applicable in the real world. Declaring your function like that now might not hurt anything, but if you were to take a job programming, you will most certainly not be using a lot of nonstandard definitions.

It was a tip that was meant to help you in the long run and, in the end, you got the answer to your specific question too. Take the information and learn from it. That's what we all have to do sometimes.