I'm fairly new and looking for some suggestions for a lab I have to complete for class. The program asks for 5 test scores all entered at once, finds the maximum and minimum score for each student, and then accumulates those 2 scores in totalHighScores and totalLowScores. The program is designed to find the average high score and average low score for x amount of students (program is terminated when a negative ID is entered). I am used to Python, and I know that Python has a built-in max/min function which made things fairly simple. I've looked around at the forum for suggestions and most of the methods used we have not even covered yet. I'm just curious what the simplest and easiest method could be to identify the max and min number after the 5 scores for each student are entered. I have posted my code below without the max/min section (obviously) thanks for any help !!
What about for the minimum? Most of the examples I were able to find shows methods on how to do it when numbers are entered individually (ex. Setting the max at 0 so every time a new number is entered that is greater than the previous max becomes the new max) but I'm a little confused on how to find max/min from a list of inputted numbers all at once
Minimum is no different from maximum; the condition and premise are simply mirrors. std::min_element
Initializing "max" to 0 works only in the case when every input greater or equal to 0. If you do validate input to prevent negative values, then the 0 is a good initial value. If you cannot do so (negative values are valid), then std::numeric_limits<float>::min() is the logical initial value for "max".
The other approach is to initialize the "max" with the first input, but then you have to test each input for whether it is the first input.
Note: your code seems to calculate the average within the input loop. You should delay that to after the loop.