返回列表 發帖

購物系統 (五)

本帖最後由 tonyh 於 2015-10-23 21:19 編輯

改寫現有購物系統, 使其搭配促銷方案.
譬如: 消費滿三千送炫光溜溜球乙個, 消費滿萬送千元折價券, 滿五千享9折優惠... 等等.
自由發揮!



本帖隱藏的內容需要回復才可以瀏覽
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5.     string tag[8]={"俠盜列車手5         ","決勝時刻:黑色行動3","虹彩六號:圍突行動 ",
  6.                    "minecraft           ","星際大戰:戰場前線 ","正當防衛3         ",
  7.                    "湯姆克蘭西:末日邊界","潛龍諜影:幻痛     "};
  8.     int price[8]={2250,2250,1790,990,2500,1900,1500,2200};
  9.     cout<<"\t※※※子耕電玩專賣店※※※"<<endl<<"本店商品保證便宜^_^"<<endl<<endl;
  10.     cout<<"[商品一覽表]"<<endl;
  11.     for(int i=0; i<8; i++){
  12.        cout<<"<"<<i+1<<">"<<tag[i]<<"\t\t"<<price[i]<<"元"<<endl;   
  13.     }
  14.     cout<<"<9>結帳去"<<"\t\t"<<endl<<endl;
  15.     cout<<"[優惠方案]\t本店滿5000元及立刻打九折"<<endl<<endl;
  16.     B:
  17.     int qty[]={0,0,0,0,0,0,0,0};
  18.     int num=0,lab,q,c, pay,coin;
  19.     A:                                                         
  20.     cout<<"請輸入商品代碼: ";
  21.     cin>>lab;
  22.     if(lab==9)
  23.       goto checkout;
  24.     else if(lab>=0){
  25.       cout<<"數量: ";
  26.       cin>>q;
  27.       num+=price[lab-1]*q;
  28.       qty[lab-1]+=q;
  29.       goto A;         
  30.     }  
  31.     else{
  32.       cout<<"輸入錯誤"<<endl;      
  33.       goto A;   
  34.     }  
  35.     checkout:
  36.     cout<<endl<<"[購物清單]"<<endl;
  37.     cout<<"----------------------------"<<endl;
  38.     for(int i=0; i<=7; i++){
  39.       if(qty[i]!=0)        
  40.         cout<<tag[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
  41.     }
  42.     cout<<"----------------------------"<<endl;  
  43.     cout<<endl<<"共"<<num<<"元"<<endl<<endl;
  44.     if(num>=5000){
  45.       cout<<"由於消費滿五千,享九折優惠!!"<<endl;              
  46.       cout<<"您只需付"<<num*0.9<<"元! 現省"<<num*0.1<<"元!"<<endl;
  47.       num*=0.9;
  48.     }              
  49.     cout<<"1-正確無誤 2-重新選購 ";
  50.     cin>>c;
  51.     if(c==2){
  52.       cout<<endl;
  53.       num=0;
  54.       goto B;
  55.     }
  56.     else if(c==1){
  57.        p:
  58.        cout<<endl;
  59.        cout<<"請您付帳: ";
  60.        cin>>pay;
  61.        if(pay<num&&pay>0){
  62.          cout<<"您付的錢不夠,還差"<<num-pay<<"元"<<endl;
  63.          goto p;         
  64.        }
  65.        else if(pay<=0){
  66.          cout<<"奧客,請付錢"<<endl;
  67.          goto p;
  68.        }
  69.        else{
  70.          coin=pay-num;   
  71.          cout<<endl<<"感謝,找您"<<coin<<"元!"<<endl;     
  72.          if(coin>=1000){   
  73.             cout<<"1000元大鈔"<<coin/1000<<"張"<<endl;
  74.             coin%=1000;
  75.          }
  76.          if(coin>=500){   
  77.             cout<<"500元大鈔"<<coin/500<<"張"<<endl;
  78.             coin%=500;
  79.          if(coin>=100){   
  80.             cout<<"100元大鈔"<<coin/100<<"張"<<endl;
  81.             coin%=100;
  82.          }
  83.          if(coin>=50){   
  84.             cout<<"50元摳摳"<<coin/50<<"枚"<<endl;
  85.             coin%=50;
  86.          }
  87.          if(coin>=10){   
  88.             cout<<"10元摳摳"<<coin/10<<"枚"<<endl;
  89.             coin%=10;
  90.          }
  91.          if(coin>=5){   
  92.             cout<<"5元摳摳"<<coin/5<<"枚"<<endl;
  93.             coin%=5;
  94.          }
  95.          if(coin>=1){   
  96.             cout<<"1元摳摳"<<coin/1<<"枚"<<endl;
  97.          }
  98.       }
  99.     }   
  100.     cout<<endl<<"再次感謝您使用本系統"<<endl;                                   
  101.     system("pause");   
  102.     return 0;
  103. }
複製代碼
ABCDEFGHIJKLMNOPQRSTUVWXYZ

TOP

  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.     re:
  19.     cout<<"請輸入商品代碼: ";
  20.     cin>>p;
  21.     if(p==8)
  22.         goto checkout;
  23.     else if(p>=1 && p<=7)
  24.     {
  25.         cout<<"數量: ";
  26.         cin>>q;
  27.         if(q<=0)
  28.         {
  29.             cout<<"輸入錯誤!"<<endl;
  30.             goto re;
  31.         }
  32.         sum+=price[p-1]*q;    //sum=sum+price[p-1]*q
  33.         qty[p-1]+=q;
  34.         goto re;
  35.     }else
  36.     {
  37.         cout<<"輸入錯誤!"<<endl;
  38.         goto re;
  39.     }
  40.     checkout:
  41.     cout<<endl<<"[購物清單]"<<endl;
  42.     cout<<"------------------------------"<<endl;
  43.     for(int i=0; i<7; i++)
  44.     {
  45.         if(qty[i]!=0)
  46.             cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
  47.     }     
  48.     cout<<"------------------------------"<<endl;     
  49.     cout<<"總共"<<sum<<"元!"<<endl<<endl;
  50.     re2:
  51.     cout<<"1-正確無誤 2-重新選購  ";
  52.     cin>>option;
  53.     if(option==1)
  54.         goto change;
  55.     else if(option==2)
  56.         goto allre;
  57.     else
  58.     {
  59.         cout<<"輸入錯誤!"<<endl;
  60.         goto re2;
  61.     }
  62.     change:
  63.     cout<<endl<<"請付帳: ";
  64.     cin>>pay;
  65.     money=pay-sum;
  66.     if(money==0)
  67.         cout<<"剛剛好!"<<endl;
  68.     else if(money<0)
  69.     {
  70.         cout<<"您付的錢不夠,還差"<<-money<<"元!"<<endl;
  71.         goto change;
  72.     }
  73.     else
  74.     {
  75.         cout<<endl<<"找您"<<money<<"元!"<<endl;
  76.         if(money>=1000)
  77.         {
  78.             cout<<"一千元鈔票"<<money/1000<<"張"<<endl;
  79.             money%=1000;   //money=money%1000;         
  80.         }
  81.         if(money>=500)
  82.         {
  83.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  84.             money%=500;        
  85.         }
  86.         if(money>=100)
  87.         {
  88.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  89.             money%=100;        
  90.         }
  91.         if(money>=50)
  92.         {
  93.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  94.             money%=50;        
  95.         }
  96.         if(money>=10)
  97.         {
  98.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  99.             money%=10;        
  100.         }
  101.         if(money>=5)
  102.         {
  103.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  104.             money%=5;        
  105.         }
  106.         if(money>=1)
  107.             cout<<"一元硬幣"<<money<<"枚"<<endl;   
  108.     }   
  109.     system("pause");   
  110.     return 0;
  111. }
複製代碼

TOP

  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

  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.     re:
  19.     cout<<"請輸入商品代碼: ";
  20.     cin>>p;
  21.     if(p==8)
  22.         goto checkout;
  23.     else if(p>=1 && p<=7)
  24.     {
  25.         cout<<"數量: ";
  26.         cin>>q;
  27.         if(q<=0)
  28.         {
  29.             cout<<"輸入錯誤!"<<endl;
  30.             goto re;
  31.         }
  32.         sum+=price[p-1]*q;    //sum=sum+price[p-1]*q
  33.         qty[p-1]+=q;
  34.         goto re;
  35.     }else
  36.     {
  37.         cout<<"輸入錯誤!"<<endl;
  38.         goto re;
  39.     }
  40.     checkout:
  41.     cout<<endl<<"[購物清單]"<<endl;
  42.     cout<<"------------------------------"<<endl;
  43.     for(int i=0; i<7; i++)
  44.     {
  45.         if(qty[i]!=0)
  46.             cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
  47.     }     
  48.     cout<<"------------------------------"<<endl;     
  49.     cout<<"總共"<<sum<<"元!"<<endl<<endl;
  50.     re2:
  51.     cout<<"1-正確無誤 2-重新選購  ";
  52.     cin>>option;
  53.     if(option==1)
  54.         goto change;
  55.     else if(option==2)
  56.         goto allre;
  57.     else
  58.     {
  59.         cout<<"輸入錯誤!"<<endl;
  60.         goto re2;
  61.     }
  62.     change:
  63.     cout<<endl<<"請付帳: ";
  64.     cin>>pay;
  65.     money=pay-sum;
  66.     if(money==0)
  67.         cout<<"剛剛好!"<<endl;
  68.     else if(money<0)
  69.     {
  70.         cout<<"您付的錢不夠,還差"<<-money<<"元!"<<endl;
  71.         goto change;
  72.     }
  73.     else
  74.     {
  75.         cout<<endl<<"找您"<<money<<"元!"<<endl;
  76.         if(money>=1000)
  77.         {
  78.             cout<<"一千元鈔票"<<money/1000<<"張"<<endl;
  79.             money%=1000;   //money=money%1000;         
  80.         }
  81.         if(money>=500)
  82.         {
  83.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  84.             money%=500;        
  85.         }
  86.         if(money>=100)
  87.         {
  88.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  89.             money%=100;        
  90.         }
  91.         if(money>=50)
  92.         {
  93.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  94.             money%=50;        
  95.         }
  96.         if(money>=10)
  97.         {
  98.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  99.             money%=10;        
  100.         }
  101.         if(money>=5)
  102.         {
  103.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  104.             money%=5;        
  105.         }
  106.         if(money>=1)
  107.             cout<<"一元硬幣"<<money<<"枚"<<endl;   
  108.     }   
  109.     system("pause");   
  110.     return 0;
  111. }
複製代碼

TOP

00000000000000

TOP

  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

返回列表