-
help me out with structs
Code:
#include <iostream.h>
struct CustomerInfo{
char name[100];
char address[100];
int lawnsize;
char daytobecut[10];
};
//---------------------------------------------
void AddCustomer()
{
cout<<"ADD"<<endl;
cout<<"Enter name to be added: ";
cin>>CustomerInfo.name;
cout<<"Enter address: ";
cin>>CustomerInfo.address;
cout<<"Enter lawn size: ";
cin>>CustomerInfo.lawnsize;
cout<<"Enter day to be cut: ";
cin>>CustomerInfo.daytobecut;
}
//---------------------------------------------
void FindCustomer()
{
}
//---------------------------------------------
void RemoveCustomer()
{
}
//---------------------------------------------
int main()
{
char menuchoice;
cout<<"Enter Display, Add, dElete, Quit: ";
cin>>menuchoice;
if(menuchoice=='A')
AddCustomer();
else if(menuchoice=='D')
FindCustomer();
else if(menuchoice=='E')
RemoveCustomer();
return (0);
}
its a shop interface :p they will eventually be 2d arrays but for now 1d i just want to be able to input one individual for now so help me out plz
-
Code:
void AddCustomer()
{
cout<<"ADD"<<endl;
cout<<"Enter name to be added: ";
cin>>CustomerInfo.name;
cout<<"Enter address: ";
cin>>CustomerInfo.address;
cout<<"Enter lawn size: ";
cin>>CustomerInfo.lawnsize;
cout<<"Enter day to be cut: ";
cin>>CustomerInfo.daytobecut;
}
You can't fill CustomerInfo with information, you need to declare an instace of it first...
Code:
void AddCustomer(CustomerInfo Cust)
{
cout<<"ADD"<<endl;
cout<<"Enter name to be added: ";
cin>>Cust.name;
cout<<"Enter address: ";
cin>>Cust.address;
cout<<"Enter lawn size: ";
cin>>Cust.lawnsize;
cout<<"Enter day to be cut: ";
cin>>Cust.daytobecut;
}
Main...
Code:
int main()
{
char menuchoice;
CustomerInfo MyCustomer;
cout<<"Enter Display, Add, dElete, Quit: ";
cin>>menuchoice;
if(menuchoice=='A')
AddCustomer(MyCustomer);
else if(menuchoice=='D')
FindCustomer(MyCustomer);
else if(menuchoice=='E')
RemoveCustomer(MyCustomer);
return (0);
}
-
Code:
#include <iostream.h>
struct CustomerInfo{
char name[100];
char address[100];
int lawnsize;
char daytobecut[10];
};
//---------------------------------------------
void AddCustomer(CustomerInfo &Customer)
{
cout<<"ADD"<<endl;
cout<<"Enter name to be added: ";
cin.getline(Customer.name,100);
cout<<"Enter address: ";
cin.getline(Customer.address,100);
cout<<"Enter lawn size: ";
cin>>Customer.lawnsize;
cout<<"Enter day to be cut: ";
cin>>Customer.daytobecut;
}
//---------------------------------------------
void FindCustomer(CustomerInfo &Customer)
{
cout<<Customer.name<<endl;
cout<<Customer.address<<endl;
cout<<Customer.lawnsize<<endl;
cout<<Customer.daytobecut<<endl;
}
//---------------------------------------------
void RemoveCustomer()
{
}
//---------------------------------------------
int main()
{
char menuchoice;
CustomerInfo Customer;
cout<<"Enter Display, Add, dElete, Quit: ";
cin>>menuchoice;
if(menuchoice=='A')
AddCustomer(Customer);
else if(menuchoice=='D')
FindCustomer(Customer);
else if(menuchoice=='E')
RemoveCustomer();
FindCustomer(Customer);
return (0);
}
wow thanks but could you help on this now why does the input mess up? it skips the enter the name and adresse part
-
After every cin.getline call, write cin.ignore(50,'\n'). This ignores the 1st 50 characters in the cin buffer or up to the newline character, whichever comes first.
Basically, what is happening is that the info from the previous input is still in the buffer so the computer thinks that the user already inputted info.
-
Code:
//---------------------------------------------
void AddCustomer(CustomerInfo &Customer)
{
cout<<"ADD"<<endl;
cout<<"Enter name to be added: ";
cin.getline(Customer.name,50);
cin.ignore(50,'\n');
cout<<"Enter address: ";
cin.getline(Customer.address,50);
cin.ignore(50,'\n');
cout<<"Enter lawn size: ";
cin>>Customer.lawnsize;
cout<<"Enter day to be cut: ";
cin>>Customer.daytobecut;
}
ok i did that but now i have another problem where customer.name never gets a value and it waits for 2 enters before going to lawn size :(
-
ok wtf! i got it fixed but im not sure why or how it work :(
Code:
//---------------------------------------------
void AddCustomer(CustomerInfo &Customer)
{
cout<<"ADD"<<endl;
cout<<"Enter name to be added: ";
cin.ignore(50,'\n');
cin.getline(Customer.name,50);
cout<<"Enter address: ";
cin.getline(Customer.address,50);
cout<<"Enter lawn size: ";
cin>>Customer.lawnsize;
cout<<"Enter day to be cut: ";
cin>>Customer.daytobecut;
}