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

TOP

返回列表