C++ 创建包含项目名称、数量和总价的收据

C++ 创建包含项目名称、数量和总价的收据,c++,C++,在用户输入No或停止购买后,如何创建一张收据,打印所选商品的所有名称、数量及其总价 我使用了开关,所以我很难找到任何关于收据的参考资料 #include <iostream> using namespace std; char acoustic, electric, drums, piano, music, equip, Yes, No, y, name; int pay, Qty; std::string again; int main() { { cout <&l

在用户输入
No
或停止购买后,如何创建一张收据,打印所选商品的所有名称、数量及其总价

我使用了
开关
,所以我很难找到任何关于收据的参考资料

#include <iostream>
using namespace std;

 char acoustic, electric, drums, piano, music, equip, Yes, No, y, name;

int pay, Qty;
std::string again;

int main()
{

{
cout << "Welcome to the Music Shop" << endl <<endl;
cout << "                                                                         ===========================                            "<<endl;
cout << "                                                                         |       Categories        |                            "<<endl;
cout << "                                                                         |  [a] Acoustic Guitar    |                            "<<endl;
cout << "                                                                         |  [b] Electric Guitar    |                            "<<endl;
cout << "                                                                         |  [c] Drums              |                            "<<endl;
cout << "                                                                         |  [d] Piano              |                            "<<endl;
cout << "                                                                         |  [e] Music Equipments   |                            "<<endl;
cout << "                                                                         ===========================                            "<<endl;


do {    
cout << "                                                                     Choose from the available categories:";
cin >> music;
cout << ""<<endl;

switch (music)
{
    case 'a':

    cout << "                                                             =============================================== "<<endl;
    cout<< "                                                             |                Acoustic Guitars             |" << endl;
    cout<< "                                                             |                                             |" << endl;
    cout<< "                                                             |           Product                 Price     |" << endl;
    cout<< "                                                             | [1] Fender Acoustic Guitar      P6,900.00   |" << endl;
    cout<< "                                                             | [2] Hartwood Acoustic Guitar    P6,300.00   |" << endl;
    cout << "                                                             =============================================== "<<endl<<endl;
    cout<<"                                                                Choose from the available Acoustic Guitars:";
    cin>>acoustic;

    if (acoustic == '1'){
        cout<<"Enter the quantity:";
        cin>>Qty;
        cout<<"("<<Qty<<")"<<"Fender Acoustic Guitar was added to your cart"<<endl;
        cout<<"Would you like to add more item? (Yes/No)"<<endl;
        cin>>again;

    }
    else if (acoustic == '2'){
        cout<<"Enter the quantity:";
        cin>>Qty;
        cout<<"("<<Qty<<")"<<"Hartwood Acoustic Guitar was added to your cart"<<endl;
        cout<<"Would you like to add more item? (Yes/No)"<<endl;
        cin>>again;
    }
    else {
        cout<<"Invalid"<<endl;
    } 

    break;

    case 'b':

    cout << "                                                             =============================================== "<<endl;
    cout<< "                                                             |                Electric Guitars             |" << endl;
    cout<< "                                                             |                                             |" << endl;
    cout<< "                                                             |           Product                 Price     |" << endl;
    cout<< "                                                             | [1] Gibson Electric Guitar      P8,500.00   |" << endl;
    cout<< "                                                             | [2] Ibanez Electric Guitar      P25,000.00  |" << endl;
    cout << "                                                             =============================================== "<<endl<<endl;
    cout<<"                                                                Choose from the available Electric Guitars:";
    cin>>electric;

        if (electric=='1'){           
        cout<<"Enter the quantity:";
        cin>>Qty;
        cout<<"("<<Qty<<")"<<"Gibson Electric Guitar was added to your cart"<<endl;
        cout<<"Would you like to add more item? (Yes/No)"<<endl;
        cin>>again; 
    }
        else if (electric=='2'){                
        cout<<"Enter the quantity:";
        cin>>Qty;
        cout<<"("<<Qty<<")"<<"Ibanez Electric Guitar was added to your cart"<<endl;
        cout<<"Would you like to add more item? (Yes/No)"<<endl;
        cin>>again;
    }
    else {
        cout<<"Invalid";
    } 

    break;

    default: 
      cout<<"Invalid"<<endl;
 }

 }
 while (again == "Yes" || again == "yes");


  cout<<"***********************************Music Shop***********************************"<<endl;
 cout<<"Name of Item                       Quantity             Total Price       "<<endl;
 cout<<"                                                                                "<<endl;
 return 0;

}
}
#包括
使用名称空间std;
原声、电、鼓、钢琴、音乐、装备、是、否、y、名称;
国际支付,数量;
std::再次使用字符串;
int main()
{
{
不能包含
使用名称空间std;
原声、电、鼓、钢琴、音乐、装备、是、否、y、名称;
国际支付,数量;
std::再次使用字符串;
长tot=0;
int sumA1=0,sumA2;
int sumB1=0,sumB2;
int QtyA1=0,QtyA2=0,QtyB1=0,QtyB2=0;
弦乐音响C1=“挡泥板原声吉他”,音响C2=“哈特伍德原声吉他”;
弦乐电吉他1=“吉布森电吉他”,电吉他2=“Ibanez电吉他”;
int main()
{
{

计算机科学的一个重要方面是“抽象”。你能试着从账单/收据、数量和价格中抽象出问题,并用对象、变量、类替换它们,并实际解释你试图完成的任务吗?写问题时,试着抓住问题。你可以用两个菜单和两个条目来解释问题。事实上,你可以通过修改问题来解决问题n对于它的要点,您可能会发现您意外地发现了@kishoredbn的观点。您的答案应该直接发布在您的答案中,而不是作为链接。您做了什么?问题出在哪里?您是如何解决的?这是一个只包含代码的答案。为了挽救它,您应该解释提问者做错了什么,突出并解释您的错误用不同的方法解决了问题。问题是我的代码没有问题,我的问题是如何解决。谢谢你的收据代码
#include <iostream>
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 << "Welcome to the Music Shop" << endl <<endl;
        cout << "                                                                         ===========================                            "<<endl;
        cout << "                                                                         |       Categories        |                            "<<endl;
        cout << "                                                                         |  [a] Acoustic Guitar    |                            "<<endl;
        cout << "                                                                         |  [b] Electric Guitar    |                            "<<endl;
        cout << "                                                                         |  [c] Drums              |                            "<<endl;
        cout << "                                                                         |  [d] Piano              |                            "<<endl;
        cout << "                                                                         |  [e] Music Equipments   |                            "<<endl;
        cout << "                                                                         ===========================                            "<<endl;


        do
        {
            cout << "                                                                     Choose from the available categories:";
            cin >> music;
            cout << ""<<endl;

            switch (music)
            {
            case 'a':

                cout << "                                                             =============================================== "<<endl;
                cout<< "                                                             |                Acoustic Guitars             |" << endl;
                cout<< "                                                             |                                             |" << endl;
                cout<< "                                                             |           Product                 Price     |" << endl;
                cout<< "                                                             | [1] Fender Acoustic Guitar      P6,900.00   |" << endl;
                cout<< "                                                             | [2] Hartwood Acoustic Guitar    P6,300.00   |" << endl;
                cout << "                                                             =============================================== "<<endl<<endl;
                cout<<"                                                                Choose from the available Acoustic Guitars:";
                cin>>acoustic;

                if (acoustic == '1')
                {
                    cout<<"Enter the quantity:";
                    cin>>Qty;
                    cout<<"("<<Qty<<")"<<"Fender Acoustic Guitar was added to your cart"<<endl;
                    cout<<"Would you like to add more item? (Yes/No)"<<endl;
                    cin>>again;

                    QtyA1+=Qty;
                    sumA1=sumA1+(6900*Qty);

                }
                else if (acoustic == '2')
                {
                    cout<<"Enter the quantity:";
                    cin>>Qty;
                    cout<<"("<<Qty<<")"<<"Hartwood Acoustic Guitar was added to your cart"<<endl;
                    cout<<"Would you like to add more item? (Yes/No)"<<endl;
                    cin>>again;
                    QtyA2+=Qty;
                    sumA2=sumA2+(6300*Qty);
                }
                else
                {
                    cout<<"Invalid"<<endl;
                }

                break;

            case 'b':

                cout << "                                                             =============================================== "<<endl;
                cout<< "                                                             |                Electric Guitars             |" << endl;
                cout<< "                                                             |                                             |" << endl;
                cout<< "                                                             |           Product                 Price     |" << endl;
                cout<< "                                                             | [1] Gibson Electric Guitar      P8,500.00   |" << endl;
                cout<< "                                                             | [2] Ibanez Electric Guitar      P25,000.00  |" << endl;
                cout << "                                                             =============================================== "<<endl<<endl;
                cout<<"                                                                Choose from the available Electric Guitars:";
                cin>>electric;

                if (electric=='1')
                {
                    cout<<"Enter the quantity:";
                    cin>>Qty;
                    cout<<"("<<Qty<<")"<<"Gibson Electric Guitar was added to your cart"<<endl;
                    cout<<"Would you like to add more item? (Yes/No)"<<endl;
                    cin>>again;
                    QtyB1+=Qty;
                    sumB1=sumB1+(8500*Qty);
                }
                else if (electric=='2')
                {
                    cout<<"Enter the quantity:";
                    cin>>Qty;
                    cout<<"("<<Qty<<")"<<"Ibanez Electric Guitar was added to your cart"<<endl;
                    cout<<"Would you like to add more item? (Yes/No)"<<endl;
                    cin>>again;

                    QtyB2+=Qty;
                    sumB2=sumB2+(25000*Qty);
                }
                else
                {
                    cout<<"Invalid";
                }

                break;

            default:
                cout<<"Invalid"<<endl;
            }

        }
        while (again == "Yes" || again == "yes");


        cout<<"***********************************Music Shop***********************************"<<endl;
        cout<<"Name of Item                       Quantity             Total Price       "<<endl;
        cout<<"                                                                                "<<endl;
        if(QtyA1>0)
            cout<<Accoustic1<<" "<<QtyA1<<" "<<sumA1<<endl;
        if(QtyA2>0)
            cout<<Accoustic2<<" "<<QtyA2<<" "<<sumA2<<endl;
        if(QtyB1>0)
            cout<<Electric1<<" "<<QtyB1<<" "<<sumB1<<endl;
        if(QtyB2>0)
            cout<<Electric2<<" "<<QtyB2<<" "<<sumB2<<endl;

        return 0;

    }
}