Hey guys. I am currently attempting an assignment that requires the user to input data into a structure.However, I can't manage to properly insert the inputs with space.(name,address etc). cin.getline spewed an error and I am out of ideas.. Here is the code..
struct customer
{
char nameC[20];
char addressD[35];
char telePhone[12];
int accountB;
};
void getInput(customer& );//declarations
for(x=0;x<10;x++)
getInput(account[x]);//In main function,skipped others not important
//The following function the problem.
void getInput(customer &account)
{
cout<<"What is the name of the customer?";
cin>>(account.nameC);
cout<<"What is the customer's address ?"<<endl;
cin>>account.addressD;
cout<<"What is the customer's phone number?"<<endl;
cin>>account.telePhone;
cout<<"What is the customer's account balance?"<<endl;
cin>>account.accountB;
return;
}//When entering the name or address with space, the loop ignores the subsequent prompt and considers I have inputted both name and address.
//cin.getline spewed |error: no matching function for call to 'std::basic_istream<char>::getline(char [20])'|
getline is the easiest way to go, so look at the documentation/ask google to find how to use it.
A pointer: with cin.geline you have got it backwards (which is why no matching function could be found).
cout<<"What is the name of the customer?";
cin>>(account.nameC);
cout<<"What is the customer's address ?"<<endl;
cin>>account.addressD;
cout<<"What is the customer's phone number?"<<endl;
cin>>account.telePhone;
cout<<"What is the customer's account balance?"<<endl;
cin>>account.accountB;
Should be :
1 2 3 4 5 6 7 8
cout << "What is the name of the customer? : ";
cin.getline(account.nameC, sizeof(account.nameC));
cout << "What is the customer's address ? : ";
cin.getline(account.addressD, sizeof(account.addressD));
cout << "What is the customer's phone number? : ";
cin.getline(account.telePhone, sizeof(account.telePhone));
cout << "What is the customer's account balance? : ";
cin >> account.accountB;