Separating higest and lowest value

This is a discussion on Separating higest and lowest value within the C Programming forums, part of the General Programming Boards category; How can I change this code so the total given number in the end will be subtracted by the largest ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 05:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21