How can I create a receipt that will print all of the name of the item chosen, quantity, and its total price after the user inputs No or stops buying? I used switch so it's hard for me to find any references about receipt.
#include using namespace std; char acoustic, electric, drums, piano, music, equip, Yes, No, y, name; int pay, Qty; std::string again; int main() < < cout > music; cout >acoustic; if (acoustic == '1')< cout>Qty; cout>again; > else if (acoustic == '2')< cout>Qty; cout>again; > else < coutbreak; case 'b': cout >electric; if (electric=='1')< cout>Qty; cout>again; > else if (electric=='2')< cout>Qty; cout>again; > else < coutbreak; default: cout > while (again == "Yes" || again == "yes"); cout <<"***********************************Music Shop***********************************"<>
The user can keep buying every time he inputs yes and it should print the receipt after saying no .
359k 69 69 gold badges 545 545 silver badges 588 588 bronze badges
asked Oct 5, 2019 at 3:21
17 5 5 bronze badges
One important aspect of Computer Science is "Abstraction". Can you try to abstract out the problem from bill/receipts, quantities and price and replace them with objects, variables, classes and explain actually what you are trying to accomplish?
Commented Oct 5, 2019 at 3:45When writing a question try to stick to the problem. You can explain the problem with two menus with two entries. In fact by reworking the question to cut it down to it's essentials you may find you've accidentally discovered the point @kishoredbn has made.
Commented Oct 5, 2019 at 4:02#include using namespace std; char acoustic, electric, drums, piano, music, equip, Yes, No, y, name; int pay, Qty; std::string again; long long tot=0; int sumA1=0,sumA2; int sumB1=0,sumB2; int QtyA1=0,QtyA2=0,QtyB1=0,QtyB2=0; string Accoustic1="Fender Acoustic Guitar",Accoustic2="Hartwood Acoustic Guitar "; string Electric1="Gibson Electric Guitar",Electric2="Ibanez Electric Guitar"; int main() < < cout > music; cout >acoustic; if (acoustic == '1') < cout>Qty; cout>again; QtyA1+=Qty; sumA1=sumA1+(6900*Qty); > else if (acoustic == '2') < cout>Qty; cout>again; QtyA2+=Qty; sumA2=sumA2+(6300*Qty); > else < coutbreak; case 'b': cout >electric; if (electric=='1') < cout>Qty; cout>again; QtyB1+=Qty; sumB1=sumB1+(8500*Qty); > else if (electric=='2') < cout>Qty; cout>again; QtyB2+=Qty; sumB2=sumB2+(25000*Qty); > else < coutbreak; default: cout > while (again == "Yes" || again == "yes"); cout<<"***********************************Music Shop***********************************"<0) cout0) cout0) cout0) cout >
359k 69 69 gold badges 545 545 silver badges 588 588 bronze badges
answered Oct 5, 2019 at 4:13
145 1 1 gold badge 2 2 silver badges 11 11 bronze badges
Your answer should be directly posted in your answer, not as a link.
Commented Oct 5, 2019 at 4:15
What did you do? What's the problem and how did you fix it?
Commented Oct 5, 2019 at 4:16
This is a code-only answer. To salvage it you should explain what the Asker had done wrong and highlight and explain what you did differently to fix the problem.