返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     system("cls");
  8.     string a[]{"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    ",};
  9.     int b[]={450,550,325,200,660,150,380};
  10.     int c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  11.     int d[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

  12.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  13.     cout<<"商品價目表"<<endl;
  14.     for(int i=0; i<7;  i++)
  15.     {
  16.         cout<<"<"<<i+1<<">"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
  17.     }
  18.     cout<<"<8>結帳"<<endl;
  19.     cout<<endl;
  20.     int x,y,z=-1,w=-1,sum=0;
  21.     re2:
  22.     cout<<"請輸入商品代碼:";
  23.     cin>>x;
  24.     if(x==8)
  25.     {
  26.         goto out;
  27.     }
  28.     else if(x>=1&&x<=7)
  29.     {
  30.         cout<<"請輸入購買數量:";
  31.         cin>>y;
  32.         z++;
  33.         sum+=b[x-1]*y;
  34.         c[z]+=y;
  35.         d[z]+=x;
  36.         goto re2;
  37.     }
  38.     else
  39.     {
  40.         cout<<"輸入錯誤"<<endl;
  41.         goto re2;
  42.     }
  43.     out:
  44.     cout<<endl;
  45.     cout<<"[購物清單]"<<endl;
  46.     cout<<"------------------------"<<endl;
  47.     for(int i=0 ; i<=30 ;i++)
  48.     {
  49.         if(d[i]!=0)
  50.         {
  51.             cout<<a[d[i]-1]<<"\t"<<b[d[i]-1]<<"元*"<<c[i]<<"個"<<endl;
  52.         }
  53.     }
  54.     cout<<"------------------------"<<endl;
  55.     cout<<endl<<"總共"<<sum<<"元!"<<endl;

  56.     system("pause");
  57.     goto re;
  58.     return 0;
  59. }
複製代碼

TOP

返回列表