Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define ENTRIES 5
- void getRoster(int jerseys[], int ratings[]);
- void printRoster(int jerseys[], int ratings[]);
- void updatePlayer(int jerseys[], int ratings[]);
- char menu();
- void displayRating(int jerseys[], int ratings[]);
- void replacePlayer(int jerseys[], int ratings[]);
- int main(void)
- {
- int jerseys[ENTRIES], ratings[ENTRIES];
- char menuOption = ' ';
- getRoster(jerseys, ratings);
- printf("ROSTER");
- printRoster(jerseys, ratings);
- printf("\n\n");
- while (1)
- {
- menuOption = menu();
- if (menuOption == 'q')
- {
- break;
- }
- else if (menuOption == 'u')
- {
- updatePlayer(jerseys, ratings);
- }
- else if (menuOption == 'a')
- {
- displayRating(jerseys, ratings);
- }
- else if (menuOption == 'o')
- {
- printRoster(jerseys, ratings);
- }
- }
- return 0;
- }
- void getRoster(int jerseys[], int ratings[])
- {
- for (int i = 0; i < ENTRIES; i++)
- {
- printf("Enter player %d's jersey number:\n", i + 1);
- scanf("%d", &jerseys[i]);
- printf("Enter player %d's rating:\n", i + 1);
- scanf("%d", &ratings[i]);
- printf("\n");
- }
- return;
- }
- void printRoster(int jerseys[], int ratings[])
- {
- for (int i = 0; i < ENTRIES; i++)
- {
- printf("\nPlayer %d -- Jersey number: %d, Rating: %d", i + 1, jerseys[i], ratings[i]);
- }
- return;
- }
- char menu()
- {
- char option;
- printf("MENU\n");
- printf("u - Update player rating\n");
- printf("a - Output players above a rating\n");
- printf("r - Replace player\n");
- printf("o - Output roster\n");
- printf("q - Quit\n");
- printf("\nChoose an option:\n");
- scanf("%c", &option);
- return option;
- }
- void updatePlayer(int jerseys[], int ratings[])
- {
- int jerseyToUpdate, index;
- printf("Enter a jersey number:\n");
- scanf("%d", &jerseyToUpdate);
- for (index = 0; index < ENTRIES; index++)
- {
- if (jerseys[index] == jerseyToUpdate)
- {
- break;
- }
- }
- printf("Enter a new rating for player:\n");
- scanf("%d", &ratings[index]);
- printf("\n");
- return;
- }
- void displayRating(int jerseys[], int ratings[])
- {
- int min;
- printf("Enter a rating:\n");\
- scanf("%d", &min);
- printf("\nABOVE %d", min);
- for (int i = 0; i < ENTRIES; i++)
- {
- if (ratings[i] >= min)
- {
- printf("\nPlayer %d -- Jersey number: %d, Rating: %d", i + 1, jerseys[i], ratings[i]);
- }
- }
- printf("\n");
- return;
- }
- void replacePlayer(int jerseys[], int ratings[])
- {
- int jerseyToUpdate, index;
- printf("Enter a jersey number:\n");
- scanf("%d", &jerseyToUpdate);
- for (index = 0; index < ENTRIES; index++)
- {
- if (jerseys[index] == jerseyToUpdate)
- {
- break;
- }
- }
- printf("Enter a new jersey number:\n");
- scanf("%d", &jerseys[index]);
- printf("Enter a rating for the new player:\n");
- scanf("%d", &ratings[index]);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement