I'm currently working on an assignment for my class. In C, I have to make a program that works with the roster of a soccer team, where you can update, replace, compare players etc. However, right now I cannot make any of the options in my menu work. This will probably be better understood with my code:
#include <stdio.h>
int main(void) {
int i, jersey, rating, newJersey, newRating, playerJerseyNumber[5], playerRating[5];
char choice;
for (i = 0; i < 5; i++)
{
printf("Enter player %d's jersey number: \n", (i + 1));
scanf("%d", &playerJerseyNumber[i]);
printf("Enter player %d's rating: \n\n", (i + 1));
scanf("%d", &playerRating[i]);
}
printf("ROSTER\n");
for (i = 0; i < 5; i++)
{
printf("Player %d -- Jersey number: %d, Rating: %d\n", (i + 1), playerJerseyNumber[i], playerRating[i]);
}
printf("\n\nMENU \nu - Update player rating \na - Output players above a rating \nr - Replace player \no - Output roster \nq - Quit\n\n");
printf("Choose an option: \n");
scanf("%c", &choice);
switch (choice) {
case 'u':
{
printf("Enter a jersey number: \n");
scanf("%d", &jersey);
printf("Enter a new rating for player: \n");
scanf("%d", &newRating);
for (i = 0; i < 5; i++)
{
if (jersey == playerJerseyNumber[i])
{
playerRating[i] = newRating;
}
}
break;
}
case 'a':
{
printf("Enter a rating: \n");
scanf("%d", &rating);
printf("\n ABOVE %d\n", rating);
for (i = 0; i < 5; i++)
{
if (playerRating[i] > rating)
{
printf("Player %d -- Jersey number: %d, Rating: %d\n", (i + 1), playerJerseyNumber[i], playerRating[i]);
}
}
break;
}
case 'r':
{
printf("Enter a jersey number: \n");
scanf("%d", &jersey);
printf("Enter a new jersey number: \n");
scanf("%d", &newJersey);
printf("Enter a rating for the new player: \n");
scanf("%d", &newRating);
for (i = 0; i < 5; i++)
{
if (jersey == playerJerseyNumber[i])
{
playerJerseyNumber[i] = newJersey;
playerRating[i] = newRating;
}
}
break;
}
case 'o':
{
printf("ROSTER\n");
for (i = 0; i < 5; i++)
{
printf("Player %d -- Jersey number: %d, Rating: %d\n", (i + 1), playerJerseyNumber[i], playerRating[i]);
}
break;
}
default:
printf("didnt work");
break;
}
return 0;
}
now, the first part of my code works correctly. however, if i try to use any of the options in the menu, they do not work. it automatically goes to the default case and prints "didn't work".
right now, i am testing with
84 7
23 4
4 5
30 2
66 9
u
4
6
o
q
which does not work, even though it should update jersey #4 to a rating of 6.
Any ideas on why this isn't working? thanks.