Thread: Separating higest and lowest value

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    17

    Separating higest and lowest value

    How can I change this code so the total given number in the end will be subtracted by the largest and smallest given number? the program asks 5 values, counts there total, checks if number exceeds the allowed limit and prints the result(dont mind the comments).

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    #define YLA 10
    #define MIN 0
    #define MAX 50                              /*enimmäismäärä tyylipisteitä*/
    
    //ESITTELYT***********************
    
    void judge(int Array[5], int min, int yla);
    void count(int Array[5], int *total);
    
    int check(int max, int *total);
    
    //PÄÄOHJELM..........*****************
    
    main()
    {
    int err=1;                                              /*Mahdollinen virhelasku*/
    int sum=0;                                            /*Hyppääjän kokonaispisteet*/
    int array[5]={0};                                    /*Tuomareitten arvostelut*/
    
    printf("Points are being counted\n\n");
    
    do{
    judge(array, MIN, YLA);                                     /*Tuomareilta pyydetään pisteitä*/
    count(array, &sum);                               /*Annetut pisteet lasketaan*/
    err = check(MAX, &sum);                    /*Tarkistetaan onko kokonaispiste kelvollinen*/
    }while(err==0);                                      
    
    printf("The total amount ");                          
    printf("of points given ");
    printf("by the judges was %d", sum);
    
    getch();
    }
    
    // FUNKTIOT**********************
    
    void judge(int Array[5], int min, int yla)
    {
    int ok_lkm;
    char roska;
    char merkki[128];
    int i;
    for(i=0; i<5; i++){
             printf("Give %d. judges points(max.10)\n", i+1);
             gets(merkki);
             ok_lkm = sscanf(merkki, "%d%c", &Array[i], &roska);
             while(ok_lkm !=1 || Array[i]<min || Array[i]>yla){
                          printf("incorrect value,\n");
                          printf("please place a correct value: \n\n");
                          gets(merkki);
                          ok_lkm = sscanf(merkki, "%d%c", &Array[i], &roska);
                          }             
             }
    }
    
    void count(int Array[5], int *total)
    {
          int i;
          for(i=0; i<5; i++){
                   *total+=Array[i];
         }
    }
    
    int check(int max, int *total){
        if(*total>max){
                       printf("\nIncompatible amount of points %d\n", *total);
                       *total=0;
                       return 0;
        }              
    }

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    17
    pretty tough, eh?

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    1. work on your indentation
    2. do not use gets - read FAQ why
    3. how do you determine the highest and lowest value among entered by user?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    17
    thanks, that didnt help at all

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Fenix View Post
    thanks, that didnt help at all
    That's strange... You mean you already know how to determine the highest and lowest values, but still do not know how to substract them from the sum?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    17
    no i dont

  7. #7
    Registered User
    Join Date
    Aug 2009
    Posts
    17
    u dont i mean

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Higest and Lowest
    By peachy900757 in forum C++ Programming
    Replies: 3
    Last Post: 01-14-2007, 06:09 AM