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.
// 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;
}
// 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.
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.