vendredi 29 octobre 2021

print statement ignored when else if statement is true

I'm attempting to write an error statement to tell the user that the "Player is not in roster". I'm using an if and else-if statement but when the else-if statement is true the print gets ignored and loops back to my defined menu.

//case r allows for a player to be replaced
case 'r':
    printf("Enter a jersey number:\n");
    int replace;
    scanf("%d", &replace);
    if (replace == jerseyNumber) { 
        for (int i = 0; i < numPlayers; ++i) {
            //if the user input matches a jersey in the array the user will input a new jersey number and rating
            printf("Enter a new jersey number:\n");
            scanf("%d", &jerseyNumber[i]);
            printf("Enter a rating for the new player:\n");
            scanf("%d", &playerRating[i]);
        }
    }
    else if (replace != jerseyNumber) {
        printf("Player not in roster.");
    }
    break;

Aucun commentaire:

Enregistrer un commentaire