Displaying Data from a Nested Structure
I am working on a program that requires a nested structure to store a departure date (day, month, year) and have declared it as such:-
Code:
struct departDate{
int day;
int month;
int year;
};
struct flightDetails{
String flightNo;
String departAirport;
String arriveAirport;
departDate date;
String departTime;
int seats;
int reserved;
double price;
};
const int listSize = 30; //number of records in array
int currentSize = 0;
I sort of understand the concept of nested structures and how to access structure members but in my program I don't set 'departure date' values I accept user input. I am unsure on how to store the user input. All references I have checked seem to initialise values for nested structures. I would like to ask the user only to enter one 'departure date' comprising of day, month and year as opposed to entering all three seperately. I thought the following code was correct:-
Code:
cout<<"Enter departure date:";
cin>>flightList[currentSize].date.day>>flightList
[currentSize].date.month>>flightList
[currentSize].date.year;
but since I am having problems displaying my records on screen (fomatting of) I cannot check if this is correct.
I am trying to display date using:
Code:
void displayAllRecords()
{ //print the data from the aray of records under suitable header
int index;
system("cls");
displayHeading();
cout<<setiosflags(ios::left);
for(index = 0; index<currentSize; index++)
{
cout<<setw(15)<<flightList[index].date.day,flightList
[index].date.month,flightList[index].date.year;
cout<<setw(15)<<flightList[index].departTime;
When I display records on screen only the day of depature date is displayed.
Its one problem after another for us programming newbies!!
Any help would be gratefully appreciated
p.s. Prelude - thanks for pointing me in the right direction.