Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <float.h>
- // print instructions
- void skriv_instruktioner() {
- 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");
- }
- // get the number of judges from the user
- int antal_domare() {
- int i = 0;
- while (i <= 2 || i >= 11) {
- printf("Number of judges (min 3 and max 10 judges)? ");
- scanf("%d", &i);
- }
- return i;
- }
- // read the score from each judge into an array
- void las_poang(double* arr, int antal) {
- for (int i = 0; i < antal; i++) {
- printf("Score from judge %d? ", i+1);
- scanf("%lf", &arr[i]);
- }
- }
- // print judge scores
- void skriv_poang(double* arr, int antal) {
- printf("Loaded scores:\n");
- for (int i = 0; i < antal; i++) {
- printf("Judge [%d]: %.1f\n", i+1, arr[i]);
- }
- }
- // compute the result
- void resultat (double* arr, int antal, double* min, double* max, double* medel) {
- *max = arr[0];
- *min = arr[0];
- for (int i = 0; i < antal; i++) {
- if (arr[i] > *max) {
- *max = arr[i];
- }
- if (arr[i] < *min) {
- *min = arr[i];
- }
- }
- }
- // print the result
- void skriv_resultat(double min, double max, double medel) {
- printf("Final result:\n");
- printf("Highest judge score: %.1f\n", max);
- printf("Lowest judge score: %.1f\n", min);
- printf("Final average score: %.1f\n",medel);
- }
- int main(void) {
- const int size = 10;
- double arr[size];
- double max;
- double min;
- double medel;
- int numberOfJudges = 0;
- skriv_instruktioner();
- numberOfJudges = antal_domare();
- printf("\n");
- las_poang (arr,numberOfJudges);
- printf("\n");
- skriv_poang (arr,numberOfJudges);
- resultat(arr,numberOfJudges,&min,&max,&medel);
- printf("\n");
- skriv_resultat(min,max,medel);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement