返回列表 發帖
本帖最後由 李知易 於 2015-4-11 11:03 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include "math.h"
  4. using namespace std;
  5. int main()
  6. {
  7.     allre:
  8.     system("cls");
  9.     int p,pay,popo,money,opt,sum=0;
  10.     string name[5]={"砍頭優惠卷","特效搖頭丸","自殺體驗卷","被打免費票","舒柔鼻涕蟲",};
  11.     int price[5]={499,1998,8888,9999,99999};
  12.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  13.     cout<<"[商品價目表]"<<endl;
  14.     int qty[5]={0,0,0,0,0};
  15.     for(int i=0; i<5; i++)
  16.     {
  17.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  18.     }
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     re:
  21.     cout<<"請輸入商品代碼: ";
  22.     cin>>p;
  23.     if(p==8)
  24.         goto checkout;
  25.     else if(p>=1 && p<=7)
  26.     {
  27.         cout<<"數量: ";
  28.         cin>>popo;
  29.         if(popo<=0)
  30.         {
  31.             cout<<"輸入錯誤!"<<endl;
  32.             goto re;        
  33.         }
  34.         sum+=price[p-1]*popo;
  35.         qty[p-1]+=popo;     
  36.     }
  37.     else
  38.     {
  39.         cout<<"輸入錯誤!"<<endl;   
  40.     }
  41.     goto re;
  42.     checkout:   
  43.     cout<<endl<<"噁心清單"<<endl;
  44.     cout<<"----------------------------------"<<endl;
  45.     for (int i=0;i<5;i++)
  46.     {
  47.         if(qty[i]!=0)
  48.             cout<<name[i]<<"\t"<<price[i]<<"元  *  "<<qty[i]<<"個"<<endl;        
  49.     }   
  50.     cout<<"----------------------------------"<<endl;
  51.    
  52.     if(sum >= 5000)
  53.     {
  54.            cout<<"你消費"<<sum<<"元,恭喜你符合滿5000打九折優惠活動!"<<endl<<endl;
  55.            cout<<"這一次的消費讓你省下!"<<(sum - round(sum * 0.9))<<"元"<<endl<<endl;
  56.            sum = round(sum * 0.9);
  57.     }
  58.     else if(sum >= 4500)
  59.     {
  60.            cout<<"你消費"<<sum<<"元,恭喜你符合滿4500送砍頭優惠卷活動!"<<endl<<endl;
  61.     }
  62.    
  63.     cout<<"總共"<<sum<<"元!"<<endl<<endl;
  64.     cout<<"1-正確無誤"<<endl<<"2-重新選購"<<endl;
  65.     cin>>opt;
  66.     if(opt==1)
  67.     {
  68.         goto change;         
  69.     }
  70.     if(opt==2)
  71.     {
  72.         goto allre;         
  73.     }
  74.     change:   
  75.         cout<<"請付錢:";
  76.         cin>>pay;
  77.     if(pay<=0)
  78.     {
  79.         cout<<endl<<"你是誰啊?!"<<endl<<endl;
  80.         goto change;      
  81.     }
  82.     money=pay-sum;
  83.     if(money<0)
  84.     {
  85.         cout<<endl<<"錢不夠喔! 還差"<<-money<<"元!"<<endl<<endl;
  86.         goto change;
  87.     }else if(money==0)
  88.     {
  89.         cout<<endl<<"剛剛好! 銘謝惠顧!"<<endl<<endl;  
  90.     }else if(money>=1000)
  91.     {
  92.         cout<<endl<<"錢太多? 全部送我吧!"<<endl<<endl;
  93.         goto change;  
  94.     }
  95.     else
  96.     {
  97.         cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
  98.         if(money>=500)
  99.         {
  100.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  101.             money%=500;   //money=money%500;            
  102.         }
  103.         if(money>=100)
  104.         {
  105.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  106.             money%=100;               
  107.         }
  108.         if(money>=50)
  109.         {
  110.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  111.             money%=50;                  
  112.         }
  113.         if(money>=10)
  114.         {
  115.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  116.             money%=10;                  
  117.         }
  118.         if(money>=5)
  119.         {
  120.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  121.             money%=5;               
  122.         }
  123.         if(money>=1)
  124.         {
  125.             cout<<"一元硬幣"<<money<<"枚"<<endl;            
  126.         }
  127.         cout<<endl;
  128.     }   
  129.     system("pause");
  130.     return 0;   
  131. }
複製代碼

TOP

返回列表