/******************************************************** * Idea from S5 programming task, converted from BASIC. * ********************************************************/ #include <stdio.h> // This function asks for the first name, surname and competitor number static void get_data (char *first_name, char *surname, int *comp_no) { printf ("What is the competitor's first name? "); scanf ("%s", first_name); printf ("What is the competitor's surname? "); scanf ("%s", surname); do { printf ("What is the competitor's number? <1 to 50> "); scanf ("%d", comp_no); } while (*comp_no < 1 || *comp_no > 50); } // This function asks for the 10 competitors' scores static void get_scores (double *scores) { int i; for (i = 0; i < 10; i++) { do { printf ("What is the score number %d? <1.0 to 6.0> ", i + 1); scanf ("%lf", &scores[i]); } while (scores[i] < 1 || scores[i] > 6); } } // This function finds the highest of the ten scores static double get_highest (double *scores) { int i; double highest; highest = scores[0]; for (i = 1; i < 10; i++) { if (scores[i] > highest) highest = scores[i]; } return highest; } // This function finds the lowest of the ten scores static double get_lowest (double *scores) { int i; double lowest; lowest = scores[0]; for (i = 1; i < 10; i++) { if (scores[i] < lowest) lowest = scores[i]; } return lowest; } /* This function finds the final score by adding up all the scores and * * subtracting the highest and lowest */ static double calculate_final_score (double *scores, double lowest, double highest) { int i; double final = 0; for (i = 0; i < 10; i++) { final += scores[i]; } final -= lowest; final -= highest; return final; } // This function counts how many judges awarded full marks static int calculate_full_marks (double *scores) { int i; int full_marks = 0; for (i = 0; i < 10; i++) { if (scores[i] == 6) ++full_marks; } return full_marks; } int main (void) { char first_name[20];// First name char surname[20]; // Surname int comp_no; // Competitor number double scores[10]; // Scores int full_marks; // No. of judges giving full marks double highest; // Highest score double lowest; // Lowest score double final; // Final score int i; // This bit calls the other functions get_data (first_name, surname, &comp_no); get_scores (scores); highest = get_highest (scores); lowest = get_lowest (scores); final = calculate_final_score (scores, lowest, highest); full_marks = calculate_full_marks (scores); /* This bit displays the ten scores, highest mark, lowest mark, final score and the number of judges awarding full marks */ printf ("Ice skating scores for %s %s %d\n", first_name, surname, comp_no); for (i = 0; i < 10; i++) printf ("Score %-2d = %.1f\n", i + 1, scores[i]); printf ("\n"); printf ("Highest Score : %.1f\n", highest); printf ("Lowest Score : %.1f\n", lowest); printf ("Final Score : %.1f\n", final); printf ("Full Marks awarded by %d judge(s)\n", full_marks); return 0; }