返回列表 發帖
  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.     int q,r;
  57.     re3:
  58.     cout<<"1-正確無誤\t2-重新輸入";
  59.     cin>>q;
  60.     if(q==1)
  61.     {
  62.         goto out2;
  63.     }
  64.     else if(q==2)
  65.     {
  66.         goto re;
  67.     }
  68.     else
  69.     {
  70.         cout<<"輸入錯誤 重新輸入";
  71.         goto re3;
  72.     }
  73.     out2:
  74.     cout<<endl;
  75.     cout<<"請付帳:";
  76.     cin>>r;
  77.     if(r<sum)
  78.     {
  79.         cout<<"您付的金額不足,還差"<<sum-r<<"元!"<<endl;
  80.         goto out2;
  81.     }
  82.     else if(r>sum)
  83.     {
  84.         cout<<endl;
  85.         cout<<"找您"<<r-sum<<"元"<<endl;
  86.         int e=r-sum;
  87.         if(e>=1000)
  88.         cout<<"1000元鈔票"<<e/1000<<"張"<<endl;
  89.         e%=1000;
  90.         if(e>=500)
  91.         cout<<"500元鈔票"<<e/500<<"張"<<endl;
  92.         e%=500;
  93.         if (e>=100)
  94.         cout<<"100元鈔票"<<e/100<<"張"<<endl;
  95.         e%=100;
  96.         if(e>=50)
  97.         cout<<"50元硬幣"<<e/50<<"個"<<endl;
  98.         e%=50;
  99.         if(e>=10)
  100.         cout<<"10元硬幣"<<e/10<<"個"<<endl;
  101.         e%=10;
  102.         if(e>=5)
  103.         cout<<"5元硬幣"<<e/5<<"個"<<endl;
  104.         e%=5;
  105.         if(z>=1)
  106.         cout<<"1元硬幣"<<e/1<<"個"<<endl;
  107.         }
  108.     else if(r==sum)
  109.     {
  110.         cout<<"剛剛好,謝謝惠顧"<<endl;
  111.     }
  112.     else
  113.     {
  114.         cout<<"輸入錯誤 重新輸入"<<endl;
  115.         goto out2;
  116.     }
  117.     system("pause");
  118.     goto re;
  119.     return 0;
  120. }
複製代碼

TOP

返回列表