I am having problems getting multiple lines to print out from a data structure that is within an array. Right now I am only getting the output for the last record entered into the array. I'm not sure if it is overwriting the records or if it is something wrong with they way it is looping. If anyone can give me some advice, it would be greatly appreciated.
Here is the code for my data structure
Code:
struct vehicles_in{
string inVin;
int inPassengerCount;
string inLuxury;
int inMpg;
char inType;
int inCapacity;
}new_vehicle [IN_VEHICLE];
Here is the code the is accepting the input
Code:
void addNewVehicle()
{
int in;
for (in=0; in<IN_VEHICLE; in++)
{
cout << "Please enter the VIN:" << endl;
cin >> new_vehicle[in].inVin;
cout << "Please enter passenger capacity for this vehicle:" << endl;
cin >> new_vehicle[in].inPassengerCount;
cout << "Is this vehicle a luxury vehicle? Y/N" << endl;
cin >> new_vehicle[in].inLuxury;
cout << "What is this vehicles miles per gallon?" << endl;
cin >> new_vehicle[in].inMpg;
cout << "Please specify vehicle type. (C)ar, (T)ruck, (V)an, or (M)otorcycle:" << endl;
cin >> new_vehicle[in].inType;
system ("clear");
menuSelect();
system("clear");
break;
}
}
Here is the code where the functions are called that print the data from the array.
Code:
void listVehicles()
{
int in;
for (in=0; in<IN_VEHICLE; in++)
{
printVehicle();
break;
}
}
void printVehicle()
{
int t;
for (t=0;t<IN_VEHICLE; t++)
{
if (!new_vehicle[t].inVin.empty())
{
cout << "Vin";
cout << " ";
cout << "Passenger Count";
cout << " ";
cout << "Luxury Vehicle";
cout << " ";
cout << "MPG";
cout << " ";
cout << "Type" << endl;;
cout << new_vehicle[t].inVin;
cout << " ";
cout << new_vehicle[t].inPassengerCount;
cout << " ";
cout << new_vehicle[t].inLuxury;
cout << " ";
cout << new_vehicle[t].inMpg;
cout << " ";
cout << new_vehicle[t].inType << endl;
}
}
}