I'm having a bit of trouble storing a 2d array of strings with C++. When I attempt to display the strings, I come up with no output. Below is what I get when I attempt to display those strings I entered. I think its how I'm storing the strings, but Im unsure at the moment how to.
Make:
Model:
Year:
and so on.
An example on what it should show:
Make: Ford
Model: Focus
Year: 1995
Color: Black
VIN: A5S179DAC5AC6G27Q
Buying Cost: $1500.00
Selling Cost: $2000.00
The program has to store different information on different cars and Add, Delete, Edit, or Display those records.
Any feedback would be very nice.
Code:
#include<iostream>
#include<string>
using namespace std;
struct Auto
{
string VIN[18][11];
string make[21][11];
string model[21][11];
string year[5][11];
string color[21][11];
string cost[9][11];
string sell[9][11];
};
void menu();
int addRecord(int[]);
int editRecord(int[]);
int delRecord(int[]);
void dispRecord(int[]);
main()
{
menu();
return 0;
}
void menu()
{
int choice, recordInfo[10]={0,0,0,0,0,0,0,0,0,0};
do{
cout<<"\n\t\tDeal 4-U Cars\n\n";
cout<<"1.\tAdd a record.\n"
<<"2.\tEdit a record\n"
<<"3.\tDelete a record\n"
<<"4.\tDisplay record.\n"
<<"5.\tQuit the Program\n";
cout<<"Choose an option: ";
cin>>choice;
switch(choice)
{
case 1: addRecord(recordInfo);
break;
/*
case 2: editRecord(recordInfo);
break;
case 3: delRecord(recordInfo);
break;
*/
case 4: dispRecord(recordInfo);
break;
case 5: cout<<"Thank you for using this program.\n";
break;
default: cout<<"You did not enter a valid choice\n";
}
}while(choice != 5);
}
int addRecord(int recordInfo[])
{
Auto info;
int count;
cout<<"In which inventory slot do you wish to store this information\n";
cin>>count;
if(recordInfo[count]==0)
{
cout<<"Please enter the make of the car: ";
cin>>info.model[0][count];
cout<<"Please enter the model of the car: ";
cin>>info.model[0][count];
cout<<"Please enter the year the car was made: ";
cin>>info.year[0][count];
cout<<"Please enter the color of the car: ";
cin>>info.color[0][count];
cout<<"Please enter the VIN number of the car: ";
cin>>info.VIN[0][count];
cout<<"Please enter the price the car was bought for: $";
cin>>info.cost[0][count];
cout<<"Please enter the selling price of the car: $";
cin>>info.sell[0][count];
recordInfo[count]=1;
}
else
{
cout<<"This record already has information.\n"
<<"Please edit the information in this record or delete it\n";
}
return recordInfo[count];
}
/*int editRecord(int recordInfo[])
{
Auto info;
cout<<"Edit a record here\n";
return recordInfo[];
}
int delRecord(int recordInfo[])
{
Auto info;
cout<<"Delete a record here\n";
return;
}*/
void dispRecord(int recordInfo[])
{
Auto info;
int count;
cout<<"Which inventory slot do you want to display the information for?\n";
cin>>count;
if(recordInfo[count]==1)
{
cout<<"\nMake: "<<info.make[0][count];
cout<<"\nModel: "<<info.model[0][count];
cout<<"\nYear: "<<info.year[0][count];
cout<<"\nColor: "<<info.color[0][count];
cout<<"\nVIN: "<<info.VIN[0][count];
cout<<"\nBuying Cost: $"<<info.cost[0][count];
cout<<"\nSelling Price: $"<<info.sell[0][count];
cout<<"\n\n";
}
else
cout<<"That record is empty.\n\n";
}