So I'm making a program that asks a user if they want to do something. The answer is as simple as Y/N. I would like the program to be able to accept both capital and lowercase "Y". Problem is, when I type while (answer == 'Y', answer == 'y')
only the lowercase "Y" is accepted. If I type while (answer == 'y', answer == 'Y')
What am I doing wrong?
(More info: "answer" is the name of my "char" variable, and I'm using the "iostream", "cstdlib", and "string" libraries)
You need to use the 'logical or' operator ||
So your code would become while (answer =='Y' || answer == 'y')
You should be using the logical operator for or
("||"):
while( answer=='Y' || answer=='y' ){
//code
}
Also, FFR:
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With