vendredi 16 août 2019

Is there a way I can shorten this if statment?

I have this really large if statement and it does not look pleasing to the eye as well as not being as efficient as possible.

I'm making a program that (depending on the users input) runs a certain block of code, for example if the user inputs 'a' the program runs a code that adds something to a file etc.

else if(ansr != 'a' && ansr != 'A' && ansr != 'r' && ansr != 'R' && ansr != 's' && ansr != 'S' && ansr != 'e' && ansr != 'E')
{
    printf("Invalid input!\n");
}

As you can see this is a really long if statement and I would like it to be shorter. Thank you

Aucun commentaire:

Enregistrer un commentaire