Trying to get 'parallel arrays" to match up and give product, price, and have user input quantity then generate a total amount at end. Very new to C++ and having trouble getting the order and sequence down right. PLEASE HELP!!
#include <iostream>
usingnamespace std;
int main()
{
string PRODUCT[3] = { "Men's Golf Ballz", "Women's Golf Ballz", "Kids Golf Ballz" };
int QUANT[3];
double PRICE[3] = { 23.00, 20.00, 15.00 };
cout << "Product #1 - Men's Golf Ballz are $23.00/dozen" << endl;
cout << "Product #2 - Women's Golf Ballz are $20.00/dozen" << endl;
cout << "Product #3 - Kid's Golf Ballz are $15.00/dozen" << endl;
double total=0;//inistialize total to zero
for (int counter = 0; counter < 3; counter++)
{
cout << "Enter quantity for Product # " << counter + 1 << ": ";
cin >> QUANT[counter];
//the whole thing can be kept inside one for loop only
total = QUANT[counter] * PRICE[counter];//you dont need to redeclare data type
}
cout<< "Your total bill is : $"<<total;
}
Product #1 - Men's Golf Ballz are $23.00/dozen
Product #2 - Women's Golf Ballz are $20.00/dozen
Product #3 - Kid's Golf Ballz are $15.00/dozen
Enter quantity for Product # 1: 3
Enter quantity for Product # 2: 6
Enter quantity for Product # 3: 4
Your total bill is : $60
Line 23 - QUANT is an array of int type. It's missing [x] and also, why is it being compared to index in the first place? Take out semi-colon at the end.
Line 25 - QUANT and PRICE have [] but missing the index. You do not specify type in front of variables. You specify type only when you declare variables.
This is the code after I fixed your last for-loop (Only the syntax, not the logic)
1 2 3 4
for (int index = 0; index < 3; index++ )
{
double total = QUANT[index] * PRICE[index];
}
Now, what are you trying to accomplish with this for-loop? You want to print the total price, right? In order to print the total price, shouldn't you include cout?
I got the code to start working without errors, but the equation is only giving me the last "products price * quantity". It's only giving me the total end price for the "Kids golf ballz" not including the other 2 products before it.