Before I respond, I want to start out by saying a good test here is to run the same data for each student and see if you come out with the correct results for both. e.g. use Student1 scores for both and then Student 2 scores for both.
Also, that doesn't set any array to 0. What it does is say that the lowest is defined as the first score - that way you don't have to include it in the for statement, although it really doesn't make much of a difference.
In any case, if your testing data that you posted is accurate, your scores for student 1 are:
65 69 67 1
The lowest grade should drop off, leaving 65, 69, and 67, added together and divided by 3 is 67. So, yep, we know the grade should be a D at 67.
Inspecting the code, you are calculating the average with each iteration.
You have:
for (int k = 0; k < 4;k++)
{
total1 += Testscore1[k];
average1 = (total1 - lowest1) / 3;
} |
I'm sure you see what is going on here, but I will go ahead and run through the statements using the data given, reminder this is for student 1. (I am also sure total1 has been initialized to 0)
k = 0
total1 = 0 + 65 = 65
average1 = 65-1/3 = 64/3 = 21 1/3
k = 1
total1 = 65 + 69 = 134
average1 = (134 - 1) / 3 = 133/3 = 41 1/3
k = 2
total1 = 134 + 67 = 201
average1 = (201-1)/3 = 200/3 = 66 2/3
k = 3
total1 = 201 + 1 = 202
average1 = (202-1)/3 = 201/3 = 67
SO if all info is correct, you should be getting the correct answer. But you should take the averaging statement out of the for loop body for efficiency. Sorry I can't help more, but it all comes down to making sure typos are not present and so on. What is the grade you are getting back for student 1? Please share the entire program again so I can look at it deeper. Thanks. Also, if you would like me to post a solution snippet, I would be glad to.
EDIT: So another testing method you could try is to have something like:
cout << "lowest: " << lowest << endl;
or
cout << "total1: " << total1 << endl;
just after the calculation is made to make sure all your numbers are in order at each iteration (inside the loop).