Thursday, December 3, 2009

I'm trying to create a program where there are 6 quizzes, how do I ignore the highest & the

For Turbo C - I have 6 quizzes, only 4 of the quizzes will be computed for the average grade (The highest and lowest grade are ignored). I'm thinking of using "loop" but I can't get the logic.



Please help.



I'm trying to create a program where there are 6 quizzes, how do I ignore the highest %26amp; the lowest?

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 %26lt;stdio.h%26gt;



#include %26lt;stdlib.h%26gt;



#define NUM 6



int intcmp(const void *i1, const void *i2)



{



int left = *(int *)i1, right = *(int *)i2;



return left %26gt;= right ? left %26gt; 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%26lt;NUM-1; i++)



{



tot+=nums[i];



fprintf(stdout, "Score: %d\n", nums[i]);



}



fprintf(stdout, "Total: %d\n", tot);



return 0;



}



--------------------------



I'm trying to create a program where there are 6 quizzes, how do I ignore the highest %26amp; the lowest?

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



I'm trying to create a program where there are 6 quizzes, how do I ignore the highest %26amp; the lowest?

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.



I'm trying to create a program where there are 6 quizzes, how do I ignore the highest %26amp; the lowest?

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-%26gt;(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.



I'm trying to create a program where there are 6 quizzes, how do I ignore the highest %26amp; the lowest?

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.

No comments:

Post a Comment

 
mortgage loan