mercredi 16 septembre 2020

if statement in C

Going through some entry level C programming and having trouble with this seemingly very simple logical operator. The first if statement is skipped if you enter last name Paul. Also trying to understand buffer size when using scanf_s.

int main(){

    char name[25];

    printf("what is your last name? ");
    printf("(Please capitalize the first letter!)\n");
    scanf_s(" %s", name, 2); 

    if ((name[0] >= 'P') && (name[0] <= 'S'))

    {
        printf("You must go to room 232 for your tickets\n ");
    }
    else
    {
        printf("You can get your tickets in the lobby\n");

    }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire