Strings/while loop

Hello people.
I am new to C++ (only know some of the basic stuff, currently going through a beginner course).

Trying to write this program and it loops, but one of the statements is displayed twice for some reason when I don't need it to.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>

using namespace std;

int main () {
    char name[50];
      
    while ( strcmp ( name, "four" ) != 0 || strcmp ( name, "4" ) != 0 || strcmp ( name, "Four" ) != 0 ) {
          
        cout << "How many lights are there?\n";
        cin.getline ( name, 50 );
        system ("CLS");
    
        if ( strcmp ( name, "four" ) == 0 || strcmp ( name, "4" ) == 0 || strcmp ( name, "Four" ) == 0 ) {
            char choice;
            cout << "Are you sure it's not 5? Y/N\n";
            cin >> choice;
            system ("CLS");
        
                if ( choice == 'y' || choice == 'Y' ) {
                    cout << "Correct, you win a cookie!\n";
                    system ("PAUSE");
                    return 0;
                }
            
                if ( choice == 'n' || choice == 'N' ) {
                    cout << "You are incorrect! Try again.\n";
                    system ("CLS");
                }
        }
  
        if ( strcmp ( name, "four" ) != 0 || strcmp ( name, "4" ) != 0 || strcmp ( name, "Four" ) != 0 ) {
            //shows this output twice
            cout << "You are incorrect! Try again.\n";
            system ("CLS");
        }
        
    }   
    
}    



What am I doing wrong? Thanks.
strcmp ( name, "four" ) != 0 || strcmp ( name, "4" ) != 0 || strcmp ( name, "Four" ) != 0 For this to be false all of the strcmp ( name, XXX ) != 0 has to give false. That only happens if name is equal to "four", "4" an "Four" at the same time which is impossible because a string can't be many strings at the same time. That means the whole condition will always give true, so the loop will never end.
Topic archived. No new replies allowed.