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;
}
}