For some reason, my if statement never runs.

In line 26, Spassword and password never match. It always runs the else statement.

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
41
42
43
44
45
46
47
48
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
string choice;
char username[50];
char password[50];
char Spassword[50];
char name[50];
cout<<"Hello, register your character.\n\n\n";
 cout<<"What is your Character's name?\n";
 cin>>username;
 cout<<"What is your password?\n";
 cin>>password;
 cout<<"Is this is?\n";
 cout<<username<<", " <<password<<"?\n"; 
 cin>>choice;
 if (choice == "Y")
 { 
            cout<<"Login:\n";
            cout<<"Password:";
            cin>>Spassword;
            if (Spassword == password)
            {
                         cout<<"hey," << username<< "\n"; 
                          }      
            else 
            {
            cout<<"Wow! You managed to lose the game, it hasnt even started!";
            cin.ignore();
            cin.ignore();
            return 0;
                 }            
            }
 if (choice == "N")
 {
            cout<<"Wow! You managed to lose the game, it hasnt even started!";
            cin.ignore();
            cin.ignore();
            return 0;
            }
cin.ignore();
cin.ignore();
return 0;
}
You can't compare char arrays with ==. All you do is to compare their starting addresses, which obviously can't be equal.
Use std::string, like you did with choice.
Thanks, I didnt know that.
Topic archived. No new replies allowed.