Loops and Paralel arrays

Hi! I'm meant to be writing a program that will compute the cost of a car and a body modification package plus a sales tax, as of right now devC++ is only giving me one error stating that the package variable was not declared, I can't figure out why that's the only compiler error it's giving me, any help is appreciated


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  #include <iostream>
#include <string>
using namespace std;

int main()

{

//declare variables
double basePrice = 0.00;
string OptionPackageCodeArray[] = {"BB", "SP", "NP", "HE", "UC"};
double PackageCostArray [] = {1500.00, 3250.00, 4575.00, 7500.00, 5220.00};
double totalCost = 0.00;
double pricewPackage =0.00;

//prompt user for package code

std::cout <<"enter package code: BB, SP, NP, HE, UC";
std::cin >> package;
PackageCostArray[] +=package;

//provide error if incorrect code
while(true)
	{ 
	
	if (package < 0 || package >5 )
	cout<< "That is not a valid option" <<endl;

//compile price with tax if correct code
	else
	{ 
cout << "enter base price";
cin>>basePrice;

// compute total with tax
pricewPackage= basePrice+package
tax= pricewPackage*.15
 totalCost= pricewPackage+tax

Cout<<"The total price of your package is:" << totalCost <<endl;
		}
	}

}
here's you variable declarement..
9
10
11
12
13
14
15
//declare variables
double basePrice = 0.00;
string OptionPackageCodeArray[] = {"BB", "SP", "NP", "HE", "UC"};
double PackageCostArray [] = {1500.00, 3250.00, 4575.00, 7500.00, 5220.00};
double totalCost = 0.00;
double pricewPackage =0.00;
//string package; 


besides,

 
PackageCostArray[] += package; //wont compile 


if you are thinking of using D method to add each of the array member it wont work..you have to loop from the array beginning until the array end...
Last edited on
it says that the error is coming from line 19, the variable 'package' is what's not declared.
I assumed that using "OptionPackageCodeArray[] +=package;" would declare it though.
as dumb as I sound I'm completely lost on how to get this program to work, I only need the loop function to bounce out incorrect package code's.
Also I need to declare the package variable so that I can put it into the algorithm to output the total cost at the end which, it needs to be a string.
What type is package supposed to have?

The compiler doesn't know; tell it.
nope..
I suggest you put string package; at line 15 to declare it
Last edited on
anyways..what are package supposed to be ??
you asked the user to input some PackageCode (which is string) but for the error checking you check it with int..

26
27
	if (package < 0 || package >5 ) //if package is a string, this wont compile unless package is some sort of int stuff
	cout<< "That is not a valid option" <<endl;
Topic archived. No new replies allowed.