Ask the user to enter unlimited amount of numbers but will terminate when the sentinel (flag) value -1 is entered (use WHILE statement).
Your program will print two outputs: maximum number and average number
The maximum number can be calculated within the main function, whereas the average value must be calculated using a separate function callable by the main function and located within the same source file (only once source file needed). Note: the average function must have one argument only named num to pass numbers from the main function.
check your code using the following entries: 2.5, 33.1, 20, -1. If the code is correct you should get the results: maximum=20, average=18.533. when I test the code, i enter the numbers and it print "enter the numbers:" non-stop. can someone help me?
olu idowu wrote:Note: the average function must have one argument only named num to pass numbers from the main function.
I think this means you are expected to use global variables (or static variables within the average function) to hold the total and counter values. Then they don't need to be passed in as arguments.
check your code using the following entries: 2.5, 33.1, 20, -1.
As has been pointed out in your other thread, a couple of those values are floating point numbers. So you must use the %f format string in your scanf(), and number must be a float (or %lf and double). Similarly your total value should be float/double, as should the max/min values in main().
You only want a while loop in main() to check for the -1 input value; you shouldn't have a while in average(). Your average function should just update the (global/static) total and counter values and calculate/return the new average value. At the moment you have an endless loop in average() because the condition (counter != 0) is not affected by any code within the loop body.