返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     allre:
  7.     system("cls");
  8.     int pay,money;
  9.     int p,q,sum=0,option;
  10.     string name[]={"遙控器車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  11.     int price[]={450,550,325,200,660,150,380};
  12.     int qty[]={0,0,0,0,0,0,0};
  13.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  14.     cout<<"[商品價目表]"<<endl;
  15.     for(int i=0; i<7; i++)
  16.          cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  17.     cout<<"(8)結帳"<<endl<<endl;
  18.     cout<<"[優惠方案] 滿五千想9折優惠!"<<endl<<endl;
  19.     re:
  20.     cout<<"請輸入商品代碼: ";
  21.     cin>>p;
  22.     if(p==8)
  23.         goto checkout;
  24.     else if(p>=1 && p<=7)
  25.     {
  26.         cout<<"數量: ";
  27.         cin>>q;
  28.         if(q<=0)
  29.         {
  30.             cout<<"輸入錯誤!"<<endl;
  31.             goto re;
  32.         }
  33.         sum+=price[p-1]*q;    //sum=sum+price[p-1]*q
  34.         qty[p-1]+=q;
  35.         goto re;
  36.     }else
  37.     {
  38.         cout<<"輸入錯誤!"<<endl;
  39.         goto re;
  40.     }
  41.     checkout:
  42.     cout<<endl<<"[購物清單]"<<endl;
  43.     cout<<"------------------------------"<<endl;
  44.     for(int i=0; i<7; i++)
  45.     {
  46.         if(qty[i]!=0)
  47.             cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
  48.     }     
  49.     cout<<"------------------------------"<<endl;     
  50.     cout<<"總共"<<sum<<"元!"<<endl<<endl;
  51.     if(sum>=5000)
  52.     {
  53.         cout<<"由於消費滿五千, 享9折優惠!"<<endl<<endl;
  54.         cout<<"您只需付"<<sum*0.9<<"元! 現省"<<sum-sum*0.9<<"元!"<<endl<<endl;
  55.         sum*=0.9;            
  56.     }
  57.     re2:
  58.     cout<<"1-正確無誤 2-重新選購  ";
  59.     cin>>option;
  60.     if(option==1)
  61.         goto change;
  62.     else if(option==2)
  63.         goto allre;
  64.     else
  65.     {
  66.         cout<<"輸入錯誤!"<<endl;
  67.         goto re2;
  68.     }
  69.     change:
  70.     cout<<endl<<"請付帳: ";
  71.     cin>>pay;
  72.     money=pay-sum;
  73.     if(money==0)
  74.         cout<<"剛剛好!"<<endl;
  75.     else if(money<0)
  76.     {
  77.         cout<<"您付的錢不夠,還差"<<-money<<"元!"<<endl;
  78.         goto change;
  79.     }
  80.     else
  81.     {
  82.         cout<<endl<<"找您"<<money<<"元!"<<endl;
  83.         if(money>=1000)
  84.         {
  85.             cout<<"一千元鈔票"<<money/1000<<"張"<<endl;
  86.             money%=1000;   //money=money%1000;         
  87.         }
  88.         if(money>=500)
  89.         {
  90.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  91.             money%=500;        
  92.         }
  93.         if(money>=100)
  94.         {
  95.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  96.             money%=100;        
  97.         }
  98.         if(money>=50)
  99.         {
  100.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  101.             money%=50;        
  102.         }
  103.         if(money>=10)
  104.         {
  105.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  106.             money%=10;        
  107.         }
  108.         if(money>=5)
  109.         {
  110.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  111.             money%=5;        
  112.         }
  113.         if(money>=1)
  114.             cout<<"一元硬幣"<<money<<"枚"<<endl;   
  115.     }   
  116.     system("pause");   
  117.     return 0;
  118. }
複製代碼

TOP

返回列表