dimanche 18 mars 2018

C++ Skipping a If Else Statement

I am attempting to code a game and it works fine up until this point:

    char response[3];
    scanf("%s", response);
    if (response[1] == 'Y' || 'y'){
        chargen = 0;
    }
    else if (response[1] == 'N'||'n'){
        chargen = 1;
    }
    else{
        printf("Not a proper response, aborting session...");
        return 0;
    }

I was attempting to ask a Yes/No question and have the game respond properly (namely, running the while loop by keeping the chargen variable at 1 if you say no and having it break the loop by changing the variable to a 0 if you say yes). However, after scanf(), this entire block of code is skipped. It just exits the program after you input any character. Any help is appreciated!

Aucun commentaire:

Enregistrer un commentaire