Howdy fellas,
I've got a project for class, and part of it involves inputting
c-string information into a struct.
Here is my code for inputting the information:
1 2 3 4 5 6 7 8 9 10 11 12
|
void addAnEntry(invType & inv){
cout << endl << "Enter ID: ";
cin.getline(inv.item[inv.totalItems].ID, 8);
cout << endl << "Enter Item Name: ";
cin.getline(inv.item[inv.totalItems].name, 20);
cout << endl << "Enter Producer: ";
cin.getline(inv.item[inv.totalItems].producer, 20);
cout << endl << "Enter Quantity: ";
cin >> inv.item[inv.totalItems].quantity;
inv.totalItems++;
cin.get(); }
|
And here is my code for an invType, and itemType.
1 2 3 4 5 6 7 8 9 10 11
|
struct itemType {
public:
char ID[8];
char name[20];
char producer[20];
int quantity; };
struct invType{
public:
itemType item[100];
int totalItems; };
|
I run into a problem when trying to run addAnEntry, the command prompt
does the following:
Enter ID:
Enter Item Name: 'Eggs'
Enter Producer: 'Eggland's Best'
Enter Quantity: '20'
|
Which isn't what I wanted. (By the way, the stuff in '' is my input.)
For some reason it doesn't take an input for ID, and also inserts an extra
line in between things that I didn't want it to insert.
Does anyone have any idea what is going on here?