Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Checking if user input is one of the characters A, W, or D

In Python I can do:

char_choice = input("What is your character choice? Please enter A, W or   D.")
while char_choice.lower() not in ["a", "w", "d"]:
    char_choice = input("You entered an incorrect character. Please try 
    again:")

Is there a way I can repeat line 2 in C++? I have tried the follow in many ways, yet it doesn't work, so I know I am doing something wrong:

    char classificationCode;
    cin >> classificationCode;
    while (classificationCode != "b" || classificationCode != "B" ||     classificationCode != "d" || classificationCode != "D" || classificationCode != "w" || classificationCode != "W");
like image 859
star Avatar asked Nov 17 '25 19:11

star


1 Answers

You're checking a char against a string, have you tried

classificationCode != 'b'
like image 127
Dylan Lawrence Avatar answered Nov 19 '25 10:11

Dylan Lawrence