We are about to switch to a new forum software. Until then we have removed the registration on this forum.
A sketch that will obtain seven judges' scores where each score must be between 1 and 10 inclusively. Your program will calculate and output the average of the five middle scores (in other words, throw out the highest and the lowest score before finding the average). This is what I want to do and I can do everything but figure out how to exclude the max and min scores from my average calculation.
Answers
If you've got an array w/ those scores already sort() & reverse():
In order to exclude the highest score, start iterating over the array from index 1.
And to exclude the lowest score, subtract 1 from the array's length for the loop's condition: O:-)
This is what I have so far, I'm not sure how you're supposed to make an array with this
Or there is this version
Let's just throw out the second version right now. How can you find the max and min scores if you are only keeping a running total or average? If you aren't recording all the scores, finding the min and max scores will be a pain.
Looking at the first version, does it seem repetitive to you at all? Does it seem to repeat the same thing a lot? Is it repeating itself? Does it say the same thing in the same way several times? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive? Is it repetitive?
This is a good indication that there is (Is it repetitive?) a better way to do things.
First of all, you have 7 scores. These variables are where you are storing the scores:
Is this repetitive? Yes. Instead of having a variable that can store one score, and then having seven of those, we can just have one LIST of scores that is seven scores long. This list of variables is commonly called an ARRAY.
Is this repetitive? Yes. We have
scores
in there twice. We can actually do this on one line:Next, look at how you ask for the scores:
Is this repetitive? Very yes. You could use a LOOP here to do the same thing many times. Since you want exactly as many scores as there are space for in the list, we can use a for loop to ask for each score:
Now that you have the scores in an array, you can sort them much easier, as GoToLoop has already shown you. Once they are sorted, it is a simple matter to sum up the middle five scores and then computer the average of them.