+ 2

how to input char with space

I already write a C++ code like below, when i run it, it will end after show: cout<<"Emplyer account"<<endl; cout<<"Register New Employee : "; how to type the code to can enter the char with space to register the new employee name. //username is admin //password is admin #include <iostream> #include <iomanip> #include <conio.h> using namespace std; int main() { string username, password ; int x; cout<<"1 = login 2 = Exit"<<endl; cin>>x; if (x==1) { cout<<"Please enter your username: "<<endl; cin>>username; cout<<"Please enter your password: "<<endl; cin>>password; if (password == "admin" && username == "admin" || password =="ADMIN" && username == "ADMIN") { cout<<"Emplyer account"<<endl; cout<<"Register New Employee : "; char name[100]; cin.getline(name,sizeof(name)); cout<<name; } else if (password == "user" && username == "user" || password == "USER" && password == "USER") { cout<<"Emplyee account"<<endl; } else {cout<<"User or password error"; cout<<"\n"; main();} } else if(x==2) cout<<"Exit"; return 0; }

26th Sep 2017, 7:08 AM
Dennis Goh
Dennis Goh - avatar
1 Réponse
+ 15
Hi, Dennis I put the solution in regEmp function for you. https://code.sololearn.com/ciBX410q7n2k
26th Sep 2017, 8:02 AM
Babak
Babak - avatar