Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <float.h>
- void print_instructions(void);
- int main(void) {
- const int size = 10;
- double arr[size];
- double max;
- double min;
- int numberOfJudges;
- print_instructions();
- // get the number of judges from the user
- numberOfJudges = 0;
- while (numberOfJudges <= 2 || numberOfJudges >= 11) {
- printf("Number of judges (min 3 and max 10 judges)? ");
- scanf("%d", &numberOfJudges);
- }
- printf("\n");
- // read the score from each judge into an array
- for (int i = 0; i < numberOfJudges; i++) {
- printf("Score from judge %d? ", i+1);
- scanf("%lf", &arr[i]);
- }
- max = arr[0];
- for (int i = 0; i < numberOfJudges; i++) {
- if (arr[i] > max) {
- max = arr[i];
- }
- }
- min = arr[0];
- for (int i = 0; i < numberOfJudges; i++) {
- if (arr[i] < min) {
- min = arr[i];
- }
- }
- printf("\n");
- printf("Loaded scores:\n");
- for (int i = 0; i < numberOfJudges; i++){
- printf("Judge [%d]: %.1f\n", i+1, arr[i]);
- }
- printf("\nFinal result: ");
- printf("\nHighest judge score: %.1f\n", max);
- printf("Lowest judge score: %.1f\n", min);
- return 0;
- }
- void print_instructions() {
- printf("\nProgram information\n");
- printf("The program reads in the number of judges and ");
- printf("the score from each judge.\nThen it calculates ");
- printf("the average score without regard to the lowest ");
- printf(" and\nhighest judge score. Finally it prints the ");
- printf("results (the highest, the\nlowest and the final ");
- printf("average score)\n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement