Here is an example that sorts the scores and ignores the lowest and the highest. Note that if the highest and the lowest are duplicated, then only one of them will be eliminated from consideration. If you want to handle duplicate lows and highs, compare the current value in the loop against the first and the last element in the array.
For the purpose of keeping this simple, this example uses a static array.
------------------------
#include
#include
#define NUM 6
int intcmp(const void *i1, const void *i2)
{
int left = *(int *)i1, right = *(int *)i2;
return left >= right ? left > right ? 1 : 0 : -1;
}
int main()
{
int nums[NUM-1] = {2,4,3,2,1,2};
int i = 0;
int tot = 0;
qsort(nums, NUM, sizeof(int), intcmp);
for (i=1; i
{
tot+=nums[i];
fprintf(stdout, "Score: %d\n", nums[i]);
}
fprintf(stdout, "Total: %d\n", tot);
return 0;
}
--------------------------
2007-11-19 00:25:13
·
answer #1
·
answered by KCNY1 4
·
0⤊
0⤋
Depends on how you are storing the results. Assuming you are storing the results in an array of sorts, it should be a simple matter of sorting the array (Using a sort algorithm of your choice), then either removing the first and last entries, or just computing the average using all but the first and last entries.
So, as pseudocode after sorting (As I'm a Java programmer rather then a C programmer):
Input: Sorted array "quiz", storing integer % results for each of n quizzes, indexed 0->(n-1)
Output: % value average of the results ignoring the highest and lowest
START
integer i
float total = 0
for i = 1 to n-2 {
total = total + quiz(i) //Where "quiz(i)" is the lookup for the result of quiz number "i"
}
total = total / (n-2)
END
This should work for any value of n providing you don't start straining the integer or float types.
It simply loops over the array, from 1 to n-2, which cuts off the first and last results. For a sorted array, this will be the highest and lowest results.
2007-11-19 08:13:47
·
answer #2
·
answered by r36787 1
·
0⤊
0⤋
Use two variables to store the highest and lowest respectively, and one to sum up all the test scores. Store the first value of the tests in both variables "high" and "low". Then check each element after the first one to determine if it is lower than "low" and if it is... assign this test score to "low". Do the same for high, instead checking if this test score is higher than "high". Once the loop completes, subtract "high" and "low" from the sum of all your tests, and then divide by the number of tests, in this case 4.
Hope that helps. Good luck.
2007-11-19 08:12:13
·
answer #3
·
answered by Rowan 2
·
0⤊
1⤋
Have one array for the quiz score.
Have another ignore array.
Loop through the quiz score and save the subscript for the lowest and highest score.
Now
ignore[lowest]=1
ignore[highest]=2
Now when you process the scores for grading make sure that ignore[i] is zero
2007-11-19 08:09:07
·
answer #4
·
answered by AnalProgrammer 7
·
0⤊
1⤋
Have a look at quiz builder. The web site is www.quiz-builder.com. It is all you want without having to do the hard work.
2007-11-23 00:33:02
·
answer #5
·
answered by ibrahim M 1
·
0⤊
0⤋