Code:
#include <iostream.h>
#include <stdlib.h>
//A structure inside another structure
struct strEntry
{
char *first_name;
char *last_name;
struct strMarriage
{
char *marriage_date;
char *marriage_city;
};
};
void enter_entry (strEntry& person); //function prototype
////////////////////////////////////////////////////////////////////////
void main()
{
strEntry name;
enter_entry(name);
}
////////////////////////////////////////////////////////////////////////
void enter_entry (strEntry& person)
{
int num_marr;
char space[100];
cout << "First Name: ";
cin.get (space,99,'\n');
cin.get ();
strcpy((person.first_name = new char[strlen(space)+1]), space);
cout << "Last Name: ";
cin.get (space,99,'\n');
cin.get ();
strcpy((person.last_name = new char[strlen(space)+1]), space);
cout << "How many times have you been married? ";
cin >> num_marr;
new strEntry.strMarriage[num_marr]; //THIS IS WRONG. WHAT SHOULD IT BE?
for (int count=1; count <= num_marr; ++count)
{
cout << "Marriage Date " << count << ": ";
cin.get (space,99,'\n');
cin.get ();
//what should be entered here???????
cout << "Marriage City " << count << ": ";
cin.get (space,99,'\n');
cin.get ();
//what should be entered here???????
}
}
I am not allowed to use global member names
The whole point of a structure inside another structure is this:
There will be several other members such as children,
so I will also need to ask how many children do they have.
If I create several structures then I will have to pass several member names, and I don't want to do that. I only want to pass one.
I can not figure this out