Thread: help on dropping score.

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    3

    help on dropping score.

    In a fruit-eating contest, there are 6 judges. Each judge gives a score out of 10 such as 7.5. The lowest
    score is discarded and the remaining scores averaged to determine the final score. If the average if 9.0 or
    above, the participant gets a golden raspberry.
    Write a program that calculates and reports score as follows:

    so far i have...

    Code:
    #include <stdio.h>
    
    int calcScore(void) {
       const int judges = 6;
       float score[judges-1], avg = 0, sum = 0;
       static int compNo = 1;
       int i;
       printf("Enter %i scores for competitor #%i: ", judges, compNo);
       for(i=-1; i<judges-1; i++) {
          scanf("%f", &score[i]);
          sum += score[i];
          //printf("%.1f\n", sum);       // debugging line
       }
       printf("\n");
       avg = sum / judges;
       printf("Result for %i: %.1f\n", compNo, avg);
    
       if(avg >= 9.0){
          printf("You win a golden raspberry!\n");
       }
       printf("Another score? 1-yes, 0-no: ");
       compNo += 1;
       return 0;
    }
    
    int main(void) {
       const int YES = 1;
       static int answer = 0;
       calcScore();
       //printf("calcScore ending...\n");  //debugging line
       scanf("%i", &answer);
    
        while(answer==0) {
             calcScore(); 
             scanf("%i", &answer);
          }
    return 0;
    }

    any help would be greatly appreciated. i'm having trouble figuring in where to put the drop lowest score and what not.

  2. #2
    Registered User
    Join Date
    Sep 2008
    Posts
    3
    Sample Run (user input in italics)
    For competitor 1 enter 6 scores: 4 5 6 7 8 9
    Result for competitor 1 is 7.00
    Another score? (1=Yes 0=No) 1
    For competitor 2 enter 6 scores: 9.5 9.5 9.5 9.5 9.5 9.5
    Result for competitor 2 is 9.50 Golden raspberry
    Another score? (1=Yes 0=No) 1
    For competitor 3 enter 6 scores: 0 0 0 0 0 0
    Result for competitor 3 is 0.00
    Another score? (1=Yes 0=No) 0

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    1. You can't access score[-1] -- you'll have to start your loop at 0.
    2. You can't drop the lowest score until you have them all; and you have to drop the lowest score before you print the averages. That rather limits where you can put that.
    3. I don't know that you've thought out your while loop quite carefully enough. Compare what gets printed to how the loop works.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    3
    i'm sorry. i'm kind of new to this and i'm not quite sure what you're saying. i agree that i'm not too good at thinking about my loops before i write them, but i was confused as to how to accept 6 scores and drop the lowest one in just a few lines of code.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, how would you know which is the smallest score? Suppose I have six numbers written on index cards, and I show them to you one at a time. You also have a single sticky note which is just big enough to write one number down (you can write a second one down, but you'll have to erase the first). How would you figure out which score to drop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting lowest and highest score from array
    By sjalesho in forum C Programming
    Replies: 6
    Last Post: 03-01-2011, 06:24 PM
  2. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 12:33 PM
  3. Frustated with mess table printing
    By benedicttobias in forum C Programming
    Replies: 6
    Last Post: 04-16-2009, 05:50 PM
  4. trouble with creating a loop to read certain number of inputs
    By import tuner650 in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2008, 07:28 PM
  5. Few errors I can't figure out
    By burn in forum C++ Programming
    Replies: 8
    Last Post: 05-07-2002, 08:43 PM