cout << "Options:\n1: Change Name\n2: Change Password\n3: Change Address\n4: Withraw\n5: Deposit\nL: Log out\n>";
while (user_input2 != '1' && user_input2 != '2' && user_input2 != '3' && user_input2 != '4' && user_input2 != '5' && user_input2 != 'L')
{
cout << "Invalid input";
}
So how do I just shortened the while conditions?
I tried doing:
cout << "Options:\n1: Change Name\n2: Change Password\n3: Change Address\n4: Withraw\n5: Deposit\nL: Log out\n>";
while (user_input2 != '1','2','3','4','5','L')
{
cout << "Invalid input";
}
but it doesn't work.
edit1: "I added more hints to what I wanted to do"
You can use the <
and >
operators for the range of '1'
to '5'
, but you'll have to handle the check for 'L'
explicitly:
while (user_input2 != 'L' && (user_input2 < '1' || user_input2 > '5'))
{
cout << "Invalid input";
}
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