-3

This does not accept any answer:

cout << "Restart yes or no: ";
cin >> retry;
while (retry != "yes" or retry != "no"){
    cout << "Restart yes or no: ";
    cin >> retry;
    system("cls");
}

If anybody can provide an alternative/fix it would be greatly appreciated.

Guanxi
  • 3,103
  • 21
  • 38
Resmik
  • 7
  • 1

2 Answers2

6

Every string is different from either "yes" or "no". You meant to loop as long as the string is different from both "yes" and "no" - this means using the logical "and" operator, not the "or" operator:

while (retry != "yes" && retry != "no") {
Mureinik
  • 297,002
  • 52
  • 306
  • 350
4

Your code has retry != yes or retry != no. This condition is a tautology, and so will always evaluate to true.

Edit your code to:

cout << "Restart yes or no: ";
cin >> retry;
while (retry != "no"){
    cout << "Restart yes or no: ";
    cin >> retry;
    system("cls");
}

If you meant to loop until a yes or no is received, then the while loop should run until the string inputted is not equal to either. You meant to use a logical AND in place of the OR. The code should read:

while (retry != "yes" && retry != "no"){
therainmaker
  • 4,253
  • 1
  • 22
  • 41
  • 1
    I like that you didn't just identify the problem, but also gave the name of the logical rule. – Feign Sep 11 '15 at 19:30