For While Loop

Hi all,

I'm working on a program that manages sales for a store and completing sales. I have a working for...while loop, however, I am attempting something a little different. I have it asking the customer if it would like to complete another sale and if the use enters '1' it will ask for the product ID's/ quantity, etc. But I would like to set it up that after the first sale, it will ask for a new sale again and it will display a new inventory.

Here is the code I have already:



cout << "Welcome To Our Store!" << endl;
cout << "Here Is Our Current Stock: " << endl;
std::cout << "\n";
cout << "Product\tID\tPrice\tQuantity\tTaxable" << endl;
cout << "101\t\t$65.00\t2\t\tYes" << endl;

cout << "102\t\t$12.50\t1\t\tNo" << endl;
cout << "103\t\t$24.50\t5\t\tNo" << endl;
cout << "104\t\t$38.75\t4\t\tYes" << endl;
cout << "105\t\t$17.80\t6\t\tYes" << endl;
cout << "106\t\t$16.50\t2\t\tNo" << endl;
cout << "107\t\t$42.85\t8\t\tYes" << endl;
cout << "108\t\t$32.99\t2\t\tYes" << endl;
cout << "109\t\t$28.75\t1\t\tYes" << endl;
cout << "110\t\t$51.55\t1\t\tNo" << endl;
std::cout << "\n";

// Loop for repeat sales
do {



// Enter the first Product ID for the first sale (-1 to exit)
cout << "Please Enter The First Product ID That You Would Like: (Type '-1' To Exit.)" << endl;
cin >> productID;


// Main loop for each sale
while (productID != -1)
{
cout << "Please Enter The Quantity You Would Like: " << endl;
cin >> quantity;

// Switch statement to determine the price, and calculate sales tax, if any, for the item.
switch (productID)
{
case 101:
price = 65.0;
taxRate = 0.075;
break;
case 102:
price = 12.5;
taxRate = 0.0;
break;
case 103:
price = 24.5;
taxRate = 0.0;
case 104:
price = 38.75;
taxRate = 0.075;
case 105:
price = 17.8;
taxRate = 0.075;
case 106:
price = 16.5;
taxRate = 0.0;
case 107:
price = 42.85;
taxRate = 0.075;
case 108:
price = 32.99;
taxRate = 0.075;
case 109:
price = 28.75;
taxRate = 0.075;
case 110:
price = 51.55;
taxRate = 0.0;
}

subtotal += price * quantity;
salesTax += price * quantity * taxRate;

// Get next Product ID
cout << "Please Enter The Next Product ID That You Would Like: " << endl;
cin >> productID;
}

// Print properly formatted output for each sale



// Another sale?
cout << "Would You Like To Continue With Another Sale?" << endl;
cout << "Please Enter '1' For Yes or '0' For No." << endl;
cin >> anotherSale;

} while (anotherSale == 1);





I would essentially like it to output a different version of the inventory while also maintaining a for...while loop for a second and third time.

Thank you in advance!
Here is my current output:

Welcome To Our Store!
Here Is Our Current Stock:

Product ID Price Quantity Taxable
101 $65.00 2 Yes
102 $12.50 1 No
103 $24.50 5 No
104 $38.75 4 Yes
105 $17.80 6 Yes
106 $16.50 2 No
107 $42.85 8 Yes
108 $32.99 2 Yes
109 $28.75 1 Yes
110 $51.55 1 No

Please Enter The First Product ID That You Would Like: (Type '-1' To Exit.)
101
Please Enter The Quantity You Would Like:
1
Please Enter The Next Product ID That You Would Like:
-1
Would You Like To Continue With Another Sale?
Please Enter '1' For Yes or '0' For No.
You haven't supplied enough to compile your program.

You haven't show the declaration for anotherSale. Is it char or int?
If it is char, your compare with 1 won't work correctly.

As for displaying the inventory, put the display logic in a function and call the function where you need to.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.


I did not post all of my code, but I have all of my variables declared as double or int.
Topic archived. No new replies allowed.