I'm no C++ developer but I was wondering why this section of code is NOT executing properly:
What happens is the user types their username and it says wrong login (regardless of whether or not it is right). Once they type it again (rightly, of course) it works, and the same goes for password. The only way I can get it to not jump to the password section is to put the cin>>username underneath the cin.getline(). I don't understand why it is executing regardless of what the user types the first time o.o I'm no C++ developer so don't mock my horrible code.
int Login(char login_un[50], char login_pw[50], int user_choice, char username[50], char password[50]){
ifstream Settings("KCLP.cfg");
cout<<"Would you like to login or create a new account?"<<endl<<"1. Login\n"<<"2. Create Account"<<endl;
cin>>user_choice;
if(user_choice==1){
cout<<"Login:";
cin.getline (login_un, 50);
cin>>username;
Settings>>username;
while (strcmp(login_un, username) !=0){
cout<<"You've mistyped your login name, please retry.\nLogin:";
cin>>login_un;
}
cout<<"Password:";
cin.getline (login_pw, 50);
cin>>username;
Settings>>password;
while (strcmp(login_pw, password) !=0){
cout<<"You've mistyped your password, please retry.\nPassword:";
cin>>login_pw;
}
CommandLine(command,version,curr_dir,cmd,wrt=1);
}
else{
CreateUser(user_un,user_pw,user_drive,size);
}
}
What happens is the user types their username and it says wrong login (regardless of whether or not it is right). Once they type it again (rightly, of course) it works, and the same goes for password. The only way I can get it to not jump to the password section is to put the cin>>username underneath the cin.getline(). I don't understand why it is executing regardless of what the user types the first time o.o I'm no C++ developer so don't mock my horrible code.