Ok, I have recently started on c++ and I wanted to make something like a bank. On my program I would be able to input a username, and a password and then I would get to input them again to login... It doesn't work. When I run the code I am about to show, the "user" (my username variable) and my "pass" (password variable) never seem to match the variables I put later when trying to login. I tried to leave messages to you so you could understand what I am saying here.
Here it is:
Please help as soon as possible!Code:#include<iostream> //do I need to add something here? using namespace std; //functions-> void signup(); char user[26]; char pass[16]; void login(); void line(); void transaction(); // <-functions (and global variables) int main() { signup(); login(); } void signup() //seems to run fine... but I am new { cout<<"Enter your user: "; cin.getline(user, 26); line(); cout<<"Now your password: "; cin.getline(pass, 16); line(); cout<<"You entered "<<user<< " " <<pass<<"\n"; } void line() { cout<<"\n"; //I cheated at inserting lines everytime lol } void login() { char x[26]; //to check the username and password char y[16]; //for login purposes... simple but problematic. cout<<"Enter your user: "; cin.getline(x, 26); line(); cout<<"Enter your password: "; cin.getline(y, 16); line(); cout<<"You entered "<<user<< " " <<pass<<"\n"; if(x == (user)) //these seem to be my main issue { if(y == (pass)) //here too { line(); transaction(); } } else { cout<<"Wrong user or password\n"; //this runs every time even when i have typed the login(); //perfect matches for logins } } void transaction() { system("PAUSE"); }



LinkBack URL
About LinkBacks



