# 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. ## 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. pretty tough, eh?

3. 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?

4. thanks, that didnt help at all

5. Originally Posted by Fenix
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?

6. no i dont

7. u dont i mean

Popular pages Recent additions