SHARE
TWEET

Untitled

a guest Oct 16th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <float.h>
  3.  
  4. // print instructions
  5. void skriv_instruktioner() {
  6.   printf("\nProgram information\n");
  7.   printf("The program reads in the number of judges and ");
  8.   printf("the score from each judge.\nThen it calculates ");
  9.   printf("the average score without regard to the lowest ");
  10.   printf(" and\nhighest judge score. Finally it prints the ");
  11.   printf("results (the highest, the\nlowest and the final ");
  12.   printf("average score)\n\n");
  13. }
  14.  
  15. // get the number of judges from the user
  16. int antal_domare() {
  17.   int i = 0;
  18.   while (i <= 2 || i >= 11) {
  19.     printf("Number of judges (min 3 and max 10 judges)? ");
  20.     scanf("%d", &i);
  21.   }
  22.   return i;
  23. }
  24.  
  25. // read the score from each judge into an array
  26. void las_poang(double* arr, int antal) {
  27.   for (int i = 0; i < antal; i++) {
  28.     printf("Score from judge %d? ", i+1);
  29.     scanf("%lf", &arr[i]);
  30.   }
  31. }
  32.  
  33. // print judge scores
  34. void skriv_poang(double* arr, int antal) {
  35.   printf("Loaded scores:\n");
  36.   for (int i = 0; i < antal; i++) {
  37.     printf("Judge [%d]: %.1f\n", i+1, arr[i]);
  38.   }
  39. }
  40.  
  41. // compute the result
  42. void resultat (double* arr, int antal, double* min, double* max, double* medel) {
  43.   *max = arr[0];
  44.   *min = arr[0];
  45.   for (int i = 0; i < antal; i++) {
  46.     if (arr[i] > *max) {
  47.       *max = arr[i];
  48.     }
  49.     if (arr[i] < *min) {
  50.       *min = arr[i];
  51.     }
  52.   }
  53. }
  54.  
  55. // print the result
  56. void skriv_resultat(double min, double max, double medel) {
  57.   printf("Final result:\n");
  58.   printf("Highest judge score: %.1f\n", max);
  59.   printf("Lowest judge score: %.1f\n", min);
  60.   printf("Final average score: %.1f\n",medel);
  61. }
  62.  
  63. int main(void) {
  64.   const int size = 10;
  65.   double arr[size];
  66.   double max;
  67.   double min;
  68.   double medel;
  69.   int numberOfJudges = 0;
  70.  
  71.   skriv_instruktioner();
  72.   numberOfJudges = antal_domare();
  73.   printf("\n");
  74.   las_poang (arr,numberOfJudges);
  75.   printf("\n");
  76.   skriv_poang (arr,numberOfJudges);
  77.   resultat(arr,numberOfJudges,&min,&max,&medel);
  78.   printf("\n");
  79.   skriv_resultat(min,max,medel);
  80.  
  81.   return 0;
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top