Hi everyone, I have this problem that I need help with and I feel like I should know how to do it as the instructions were super clear, I just dont think im sure about where to start and if im even doing this right. After hours of googling and trying to understand I still dont understand how to break down the arrays and to check whether the input for the letter code is correct. Im still fairly new to all of this and these are new concepts to me
"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.
This question was previously asked on the forum but I also did not understand that
I know I have to do this so far:
cout << "Enter Base Price for Car:"
cin >> basePrice
std::string userInput;
std::cout << "Enter the 2-letter code: ";
std::getline(std::cin, userInput);
bool isValid = false;
for (int i = 0; i < 5; i++)
{
if (userInput == optionPackageCodeArray[i])
{
isValid = true;
subTotal = basePrice + packageCostArray [i];
finalPrice = subTotal * .015;
//Your calculations go here. The current "i" represents the same position
//in all the arrays. So "BB" goes together with "Base" which goes together with "1500.0"
//You can access them by doing "packageCostArray[i] = ..."
//And would my final displayed result go here as well?
}
else
{
isValid = false;
}
}
if (isValid == false)
{
std::cout << "Bad input!";
}
system ("pause");
std::cin.get();
return 0;}
I debugged what I had before putting the base price input and it worked up to the point where it did not recognize the Package code, if I tried any of them it just told me I had a bad input
And how do you reply in code?
You were pretty much almost done. You have to double check that you've put all the semi-colons (;) where they should be. Those were most of your errors. Also, there must NOT be an "else" which sets isValid to false. isValid is initialized to false when it is declared. So once it becomes true it mustn't become false again... which is what was happening.