Three Parallel Arrays

Hi, I'm new to this forum, so im sorry if i do not ask for help correctly, i am taking a c++ class online and i have to do a program with arrays and i just cannot grasp the concept. Been trying to figure out this program all night and i work in less than two hours, can someone point in the right direction as how to start this, i just cannot even begin to put the code together, thanks in advance.

"You are to write a program which inputs the base price of a car. Then, the program will input in a 2-letter code (a string) which corresponds to an option package.

All the 2 letter codes will be in an array (string), along with the corresponding cost of the package in a parallel array (doubles), and there is also another array with the name of the package (string).

Here is the data for the 3 parallel arrays:

OptionPackageCodeArray PackageCostArray PackageNameArray
BB 1500.00 Base
SP 3250.00 Sport
NP 4575.00 Intermediate
HE 7500.00 Luxury
UC 5220.00 User specified


Your program first has to determine if the 2-letter code input by the user is valid. You are required to use a loop to check the input against each item in the optionPackageCodeArray. Begin with the first item then "walk" down through the array. If the code does NOT exist on the list, display an error message and stop. If the code is valid, do some calculation and displaying. First, add the base price to the package cost from the array and get a subtotal. Then, calculate 15% of the subtotal for taxes and fees and add that to the subtotal for a final price. Display the final price and the full name of the package from the last array, then stop.
It would make sense to hold all the car details together. But that would require use of a language feature call a struct, a way of defining a group of field that form a record.

Because you can't use that, but have probably been introduced to arrays, you're asked to represent each of the three columns as arrays. So you have: OptionPackageCodeArray, PackageCostArray and PackageNameArray.

OptionPackageCodeArray is an array of strings, so it looks like:
1
2
3
4
5
6
7
8
std::string OptionPackageCodeArray[] =
{
    "BB",
    "SP",
    "NP",
    "HE",
    "UC"
};

You're expected to declare the other arrays too, so you can sort of copy what I did for the first one, but remember that PackageCostArray is an array of doubles rather than strings.

Going thru what you're expected to do, it's pretty much spelled out. Your program first has to determine if the 2-letter code input by the user is valid.

1. You are required to use a loop to check the input against each item in the optionPackageCodeArray.
2. Begin with the first item then "walk" down through the array. If the code does NOT exist on the list, display an error message and stop.
3. If the code is valid, do some calculation and displaying.
4. First, add the base price to the package cost from the array and get a subtotal.
5. Then, calculate 15% of the subtotal for taxes and fees and add that to the subtotal for a final price.
6. Display the final price and the full name of the package from the last array, then stop.

What's the problem?
Thanks for your reply, and sorry man I haven't had that much time to look at the arrays.

Here is what i have so far, is it looking good at all? I'm really short on time work a double today at work only had an hour break.

#include <iostream>
using namespace std;

int main( )
{
string PackageName = "";
string OptionPackageCodeArray[5] ={ "BB", "SP", "NP", "HE","UC"};

//Prompt the user for performer name
cout << "Enter the package name (type end to quit): ";
cin >> PackageName;

double PackageCostArray[5] = { 1500, 3250, 4575, 7500, 5220 };
std::string PackageNameArray[] =
{
"Base",
"Sport",
"Intermediate Level",
"Luxury",
"User Specified"
};

system("pause");
return 0;
} //end of main
Topic archived. No new replies allowed.