+ 1

Why isn't my code working right?

If i enter an address with 10 or more letters it then dosnt let me input the phone number #include <iostream> #include <string> using namespace std; int Confirm(); struct Info { string name; string Address; string PhoneNum; }; int main() { Info person; cout<<"Please enter your name: "; cin>>person.name; cout<<"Please enter your address: "; cin>>person.Address; cout<<"Please enter your Phone Number: "; cin>>person.PhoneNum; cout<<"Information saved"<<endl; cout<<"\nPlease confirm your information"<<endl; cout<<"Your name is "<<person.name; cout<<"Your address is "<<person.Address; cout<<"Your Phone Number is "<<person.PhoneNum; }

18th Jul 2017, 12:05 AM
Chris
Chris - avatar
4 Answers
+ 11
cin on its own collects characters until it encounters a space. If the address has spaces, use this: getline(cin, person.Address); I also recommend you do this for name (if it implies a full name).
18th Jul 2017, 12:18 AM
Tamra
Tamra - avatar
+ 7
does the address contain spaces?
18th Jul 2017, 12:16 AM
jay
jay - avatar
+ 2
Yeah when I put spaces it does not work for some reason
18th Jul 2017, 12:18 AM
Chris
Chris - avatar
+ 2
@Tamra it works thank you
18th Jul 2017, 12:21 AM
Chris
Chris - avatar