Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <float.h>
  3.  
  4. void print_instructions(void);
  5.  
  6. int main(void) {
  7. const int size = 10;
  8. double arr[size];
  9. double max;
  10. double min;
  11. int numberOfJudges;
  12.  
  13. print_instructions();
  14.  
  15. // get the number of judges from the user
  16. numberOfJudges = 0;
  17. while (numberOfJudges <= 2 || numberOfJudges >= 11) {
  18. printf("Number of judges (min 3 and max 10 judges)? ");
  19. scanf("%d", &numberOfJudges);
  20. }
  21. printf("\n");
  22.  
  23. // read the score from each judge into an array
  24. for (int i = 0; i < numberOfJudges; i++) {
  25. printf("Score from judge %d? ", i+1);
  26. scanf("%lf", &arr[i]);
  27. }
  28.  
  29. max = arr[0];
  30. for (int i = 0; i < numberOfJudges; i++) {
  31. if (arr[i] > max) {
  32. max = arr[i];
  33. }
  34. }
  35. min = arr[0];
  36. for (int i = 0; i < numberOfJudges; i++) {
  37. if (arr[i] < min) {
  38. min = arr[i];
  39. }
  40. }
  41. printf("\n");
  42. printf("Loaded scores:\n");
  43. for (int i = 0; i < numberOfJudges; i++){
  44. printf("Judge [%d]: %.1f\n", i+1, arr[i]);
  45. }
  46. printf("\nFinal result: ");
  47. printf("\nHighest judge score: %.1f\n", max);
  48. printf("Lowest judge score: %.1f\n", min);
  49.  
  50. return 0;
  51. }
  52.  
  53. void print_instructions() {
  54. printf("\nProgram information\n");
  55. printf("The program reads in the number of judges and ");
  56. printf("the score from each judge.\nThen it calculates ");
  57. printf("the average score without regard to the lowest ");
  58. printf(" and\nhighest judge score. Finally it prints the ");
  59. printf("results (the highest, the\nlowest and the final ");
  60. printf("average score)\n\n");
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement