Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define NBSPORTIFSMAX 7
- #define NBEVENMAX 10
- #define NAMELENMAX 33
- int inputRoutine(char inputNames[NBSPORTIFSMAX][33]);
- int getEventsNoRoutine(void);
- void inputScoreRoutine(signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX], int events, int names, char inputNames[NBSPORTIFSMAX][NAMELENMAX]);
- void min(signed short int minScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
- void mid(signed short int midScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
- void max(signed short int maxScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
- void bestPlayer(signed short int bestScores[NBSPORTIFSMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
- void midScores(signed short int midScores[NBSPORTIFSMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
- void bubbleSort(short int numbers[NBEVENMAX], int size);
- int award(signed short int inputScores[NBEVENMAX], int events);
- int main(int argc, char **argv)
- {
- char inputNames[NBSPORTIFSMAX][NAMELENMAX];
- signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX];
- signed short int maxScores[NBEVENMAX], midScores[NBEVENMAX], mid2Scores[NBSPORTIFSMAX], minScores[NBEVENMAX];
- signed short int bestScores[NBSPORTIFSMAX];
- int i = 0, j = 0, prnVal = 0;
- int inputEvents = 0, inputNamesVal = 0;
- inputNamesVal = inputRoutine(inputNames);
- while(!inputEvents || inputEvents > NBEVENMAX)
- {
- inputEvents = getEventsNoRoutine( );
- if(inputEvents <= NBEVENMAX && inputEvents > 0)
- break;
- else
- printf("error: there must be more than one event and at most %i events.\n", NBEVENMAX);
- }
- inputScoreRoutine(inputScores, inputEvents, inputNamesVal, inputNames);
- min(minScores, inputEvents, inputNamesVal, inputScores);
- mid(midScores, inputEvents, inputNamesVal, inputScores);
- max(maxScores, inputEvents, inputNamesVal, inputScores);
- midScores(mid2Scores, inputEvents, inputNamesVal, inputScores);
- bestPlayer(bestScores, inputEvents, inputNamesVal, inputScores);
- while(1)
- {
- system("cls");
- printf("Enter player who's data to print:\n");
- for(i = 0; i < inputNamesVal; i++)
- printf("\t%i - %s\n", i, inputNames[i]);
- printf("\n\n%i - Best players in each event\n%i - Median of event scores\nX - Exit\n\nEnter option to print: ", i, i+1);
- scanf("%i", &prnVal);
- if(prnVal == inputNamesVal)
- {
- for(j = 0; j < 99; j++)
- putchar('=');
- for(j = 0; j < inputNamesVal; j++)
- printf("Event %3i, Winner: %s\n", j + 1, inputNames[bestScores[j]]);
- putchar('\n');
- }
- else if(prnVal == i + 1)
- {
- for(j = 0; j < inputEvents; j++)
- printf("Event: %i, median: %i\n", j + 1, mid2Scores[j]);
- }
- else if(prnVal == 'X')
- break;
- else
- {
- for(j = 0; j < 99; j++)
- putchar('=');
- printf("\n%15s | ", "Event ID");
- for(j = 0; j < inputEvents; j++)
- printf("%3i ", j + 1);
- printf("Min Mid Max Award\n");
- for(j = 0; j < 99; j++)
- putchar('=');
- putchar('\n');
- printf("%15s | ", inputNames[prnVal]);
- printf("%3i %3i %3i %5s", minScores[prnVal], midScores[prnVal], maxScores[prnVal], (award(inputScores[prnVal], inputEvents)) ? "YES" : "NO");
- putchar('\n');
- for(j = 0; j < 99; j++)
- putchar('=');
- printf("\n\npress enter to continue...");
- fflush(stdin); getchar( );
- }
- }
- return(0);
- }
- int inputRoutine(char inputNames[NBSPORTIFSMAX][33]) // take argument by full reference since we know the bounds
- {
- int i = 0;
- printf("Enter the names of the participants, press enter to finish input:\n");
- // store names in buffer
- for(i = 0; i < NBSPORTIFSMAX; i++)
- {
- printf("%.2i: ", i + 1);
- fgets(inputNames[i], NAMELENMAX - 1, stdin);
- if(inputNames[i][0] == '\n') // break if input is blank
- break;
- inputNames[i][(strlen(inputNames[i]) - 1)] = 0; // removes the newline character
- }
- return(i);
- }
- int getEventsNoRoutine(void)
- {
- int input;
- printf("Enter number of events: ");
- scanf("%i", &input);
- return(input);
- }
- void inputScoreRoutine(signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX], int events, int names, char inputNames[NBSPORTIFSMAX][NAMELENMAX])
- {
- int menuOption, loopControl = 1, i = 0, j = 0;
- system("cls");
- printf("Input Scores Menu\n\nInput by:\n\t0: Participant name\n\t1: Event\n\n");
- while(loopControl)
- {
- printf("Option: ");
- scanf("%i", &menuOption);
- switch(menuOption)
- {
- case 0:
- loopControl ^= loopControl; //Nice touch :P 'cos we are 1337
- system("cls");
- for(i = 0; i < names; i++)
- {
- printf("Input for: %s (%.2i)\n", inputNames[i], i + 1);
- for(j = 0; j < events; j++)
- {
- printf("Event %.2i: ", j + 1);
- scanf("%i", &inputScores[i][j]);
- }
- }
- break;
- case 1:
- loopControl ^= loopControl;
- system("cls");
- for(i = 0; i < events; i++)
- {
- printf("Input for event %.2i:\n", i + 1);
- for(j = 0; j < names; j++)
- {
- printf("Input for %s (%.2i): ", inputNames[j], j + 1);
- scanf("%i", &inputScores[j][i]);
- }
- }
- break;
- default:
- printf("error: invaild menu option.\n");
- break;
- }
- }
- }
- void min(signed short int minScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX])
- {
- signed short int temp, i = 0, j = 0;
- for(i = 0; i < names; i++)
- {
- temp = inputScores[i][0];
- for(j = 0; j < events; j++)
- if(temp > inputScores[i][j])
- temp = inputScores[i][j];
- minScores[i] = temp;
- }
- }
- void mid(signed short int midScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX])
- {
- signed short int tempArray[NBEVENMAX], temp, i = 0, j = 0;
- for(i = 0; i < names; i++)
- {
- for(j = 0; j < events; j++)
- tempArray[j] = inputScores[i][j];
- bubbleSort(tempArray, events);
- midScores[i] = tempArray[(int)(events/2)]; // if even will take the lower value
- }
- }
- void max(signed short int maxScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX])
- {
- signed short int temp, i = 0, j = 0;
- for(i = 0; i < names; i++)
- {
- temp = inputScores[i][0];
- for(j = 0; j < events; j++)
- if(temp < inputScores[i][j])
- temp = inputScores[i][j];
- maxScores[i] = temp;
- }
- }
- void bestPlayer(signed short int bestScores[NBSPORTIFSMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX])
- {
- int i = 0, j = 0, temp = 0;
- for(i = 0; i < events; i++)
- {
- temp = inputScores[0][i];
- for(j = 0; j < names; j++)
- if(temp > inputScores[j][i])
- temp = inputScores[j][i];
- bestScores[i] = temp;
- }
- }
- int award(signed short int inputScores[NBEVENMAX], int events)
- {
- int i = 0, temp;
- temp = inputScores[i];
- for(i = 1; i < events; i++)
- {
- if(temp > inputScores[i])
- break;
- else
- {
- temp = inputScores[i];
- continue;
- }
- }
- return((i == events) ? 1 : 0);
- }
- void bubbleSort(short int numbers[NBEVENMAX], int size)
- {
- int i, j, temp;
- for(i = (size - 1); i >= 0; i--)
- {
- for(j = 1; j <= i; j++)
- {
- if(numbers[j-1] > numbers[j])
- {
- temp = numbers[j-1];
- numbers[j-1] = numbers[j];
- numbers[j] = temp;
- }
- }
- }
- }
- void midScores(signed short int midScores[NBSPORTIFSMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
- {
- signed short int tempArray[NBSPORTIFSMAX], temp, i = 0, j = 0;
- for(i = 0; i < events; i++)
- {
- for(j = 0; j < names; j++)
- tempArray[j] = inputScores[j][i];
- bubbleSort(tempArray, names);
- midScores[i] = tempArray[(int)(names/2)]; // if even will take the lower value
- }
- }
Add Comment
Please, Sign In to add comment