I am working on an assignment where I have to create a program that the user can personalize the options in buying a new car. I have a .txt file with two columns, one column has the price(double), the other column has the option(string). I want to have two parallel arrays that I can use so that the user can enter the string option and a vector will automatically update the price of the car. This is the .txt file and its contents.
5000.0 Leather Seats
1000.0 DVD System
800.0 10 Speakers
1400.0 Navigation System
500.0 CarPlay
500.0 Android Auto
2000.0 Lane Monitoring
800.0 3/36 Warranty
999.0 6/72 Warranty
1500.0 Dual Climate
225.0 Body Side Molding
49.0 Cargo Net
87.0 Cargo Organizer
700.0 450W Audio
1000.0 Heated Seats
Edit: I apologize for not putting enough information, I am new here. So This is the code I have so far:
void optionsLoop();
void printOptions();
char selectModel();
///function prototypes
int main(int argc, char const *argv[])
{
ifstream inStream;
int menuChoice;
char model;
const int SIZE = 30;
inStream.open("options.txt");
if (inStream.fail())
{
cout << "Error opening file";
exit (0);
}
do
{
optionsLoop ();
cout << "Enter choice: ", cin >> menuChoice;
switch (menuChoice)
{
case 1:
model = selectModel();
break;
case 2:
printOptions();
}
}
while(menuChoice !=6);
return 0;
}/// main
void optionsLoop()
{
cout << " " <<endl;
cout << "Bob Cat Auto Dealership" << endl;
cout << "Please select choice" << endl;
cout << "1. Select a model (E, L, X)" << endl;
cout << "2. Display available options and prices" << endl;
cout << "3. Add an option" << endl;
cout << "4. Remove an option" << endl;
cout << "5. Cancel Order" << endl;
cout << "6. Quit" << endl;
}
char selectModel()
{
char model;
cout << "Enter the model (E, L, X ) : ";
cin >> model;
model = toupper(model);
return model;
}
So I have a file called options.txt that has the two columns, the right column has the name of the option and the left is the price. I use ifstream to read the information into the program.
I would like to read the file as two parallel arrays so I could use it in the rest of my program.
For example for option 1 in the options loop, I need to have the user choose which model he/she wants,then display the starting price. Whatever options the user chooses in option 3 of the menu would increase the price of the car. So if the user types in leather seats, the price would increase by $5000. This is why I need them parallel.
I hope this clarifies things. I am new to arrays and stackoverflow!