Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #define ENTRIES 5
  3. void getRoster(int jerseys[], int ratings[]);
  4. void printRoster(int jerseys[], int ratings[]);
  5. void updatePlayer(int jerseys[], int ratings[]);
  6. char menu();
  7. void displayRating(int jerseys[], int ratings[]);
  8. void replacePlayer(int jerseys[], int ratings[]);
  9. int main(void)
  10. {
  11. int jerseys[ENTRIES], ratings[ENTRIES];
  12. char menuOption = ' ';
  13. getRoster(jerseys, ratings);
  14. printf("ROSTER");
  15. printRoster(jerseys, ratings);
  16. printf("\n\n");
  17. while (1)
  18. {
  19. menuOption = menu();
  20. if (menuOption == 'q')
  21. {
  22. break;
  23. }
  24. else if (menuOption == 'u')
  25. {
  26. updatePlayer(jerseys, ratings);
  27. }
  28. else if (menuOption == 'a')
  29. {
  30. displayRating(jerseys, ratings);
  31. }
  32. else if (menuOption == 'o')
  33. {
  34. printRoster(jerseys, ratings);
  35. }
  36. }
  37. return 0;
  38. }
  39. void getRoster(int jerseys[], int ratings[])
  40. {
  41. for (int i = 0; i < ENTRIES; i++)
  42. {
  43. printf("Enter player %d's jersey number:\n", i + 1);
  44. scanf("%d", &jerseys[i]);
  45. printf("Enter player %d's rating:\n", i + 1);
  46. scanf("%d", &ratings[i]);
  47. printf("\n");
  48. }
  49. return;
  50. }
  51. void printRoster(int jerseys[], int ratings[])
  52. {
  53. for (int i = 0; i < ENTRIES; i++)
  54. {
  55. printf("\nPlayer %d -- Jersey number: %d, Rating: %d", i + 1, jerseys[i], ratings[i]);
  56. }
  57. return;
  58. }
  59. char menu()
  60. {
  61. char option;
  62. printf("MENU\n");
  63. printf("u - Update player rating\n");
  64. printf("a - Output players above a rating\n");
  65. printf("r - Replace player\n");
  66. printf("o - Output roster\n");
  67. printf("q - Quit\n");
  68. printf("\nChoose an option:\n");
  69. scanf("%c", &option);
  70. return option;
  71. }
  72. void updatePlayer(int jerseys[], int ratings[])
  73. {
  74. int jerseyToUpdate, index;
  75. printf("Enter a jersey number:\n");
  76. scanf("%d", &jerseyToUpdate);
  77. for (index = 0; index < ENTRIES; index++)
  78. {
  79. if (jerseys[index] == jerseyToUpdate)
  80. {
  81. break;
  82. }
  83. }
  84. printf("Enter a new rating for player:\n");
  85. scanf("%d", &ratings[index]);
  86. printf("\n");
  87. return;
  88. }
  89. void displayRating(int jerseys[], int ratings[])
  90. {
  91. int min;
  92. printf("Enter a rating:\n");\
  93. scanf("%d", &min);
  94. printf("\nABOVE %d", min);
  95. for (int i = 0; i < ENTRIES; i++)
  96. {
  97. if (ratings[i] >= min)
  98. {
  99. printf("\nPlayer %d -- Jersey number: %d, Rating: %d", i + 1, jerseys[i], ratings[i]);
  100. }
  101. }
  102. printf("\n");
  103. return;
  104. }
  105. void replacePlayer(int jerseys[], int ratings[])
  106. {
  107. int jerseyToUpdate, index;
  108. printf("Enter a jersey number:\n");
  109. scanf("%d", &jerseyToUpdate);
  110. for (index = 0; index < ENTRIES; index++)
  111. {
  112. if (jerseys[index] == jerseyToUpdate)
  113. {
  114. break;
  115. }
  116. }
  117. printf("Enter a new jersey number:\n");
  118. scanf("%d", &jerseys[index]);
  119. printf("Enter a rating for the new player:\n");
  120. scanf("%d", &ratings[index]);
  121. return;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement