返回列表 發帖

購物系統 [五]

本帖最後由 tonyh 於 2015-9-18 21:03 編輯

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

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

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main ()
  5. {
  6.   start:
  7.   cout<<"∮∮∮愛心甜點店店∮∮∮"<<endl;
  8.   cout<<"~商品價目表~"<<endl;  
  9.   string n[5]={"卡布奇諾   ","濃郁黑咖啡 ","焦糖瑪奇朵 ","黑森林蛋糕  ","原味起司蛋糕",};
  10.   int p[5]={160,210,125,95,65};
  11.   int qty[5]={0,0,0,0,0};
  12.   int a,q,sum=0;
  13.   int option;
  14.   int pay,money;
  15.   for(int i=0; i<=4; i++)
  16.   {
  17.           cout<<"("<<i+1<<")"<<"  "<<n[i]<<"   "<<p[i]<<endl;
  18.   }
  19.   cout<<"(6)  結帳"<<endl<<endl;
  20.   cout<<"買5000就送500cc鴛鴦奶茶一杯呦!"<<endl;
  21.   if(sum>=5000)
  22.   cout<<"恭喜您獲得500cc鴛鴦奶茶一杯"<<endl;
  23.   re:
  24.   cout<<"請輸入商品代碼: ";
  25.   cin>>a;
  26.   if(a>=1 && a<=5)
  27.   {
  28.          cout<<"數量: ";
  29.          cin>>q;
  30.          if(q>=1)      
  31.          {
  32.                 sum=sum+p[a-1]*q;
  33.                 qty[a-1]=qty[a-1]+q;
  34.                 goto re;
  35.          }else
  36.          {
  37.                 cout<<"輸入錯誤!"<<endl;
  38.                 goto re;  
  39.          }
  40.   }else if(a==6)
  41.   {
  42.          goto checkout;
  43.   }else
  44.   {     
  45.          cout<<"輸入錯誤!"<<endl;
  46.          system ("pause");
  47.          goto re;
  48.   }
  49.   checkout:
  50.   cout<<"[購物清單]"<<endl;
  51.   cout<<"=========================="<<endl;
  52.   for(int i=0; i<=6; i++)
  53.   {
  54.         if(qty[i]!=0)   
  55.             cout<<n[i]<<"\t"<<p[i]<<"元 * "<<qty[i]<<"個"<<endl;      
  56.   }
  57.   cout<<"=========================="<<endl;
  58.   cout<<"總共 "<<sum<<"元!"<<endl<<endl;
  59.   if(sum>=5000)
  60.   {
  61.             cout<<"恭喜您獲得500cc鴛鴦奶茶一杯"<<endl;
  62.   }
  63.   
  64.   cout<<"(1)正確無誤(2)重新輸入"<<endl;
  65.   cin>>option;
  66.   if(option==1)
  67.     {
  68.          goto pay;
  69.     }else if(option==2)
  70.     {
  71.          system("cls");      
  72.          goto start;  
  73.     }else
  74.     {
  75.          cout<<"輸入錯誤!"<<endl;
  76.          goto start;
  77.     }
  78.     pay:
  79.     cout<<endl<<"請付帳: ";
  80.     cin>>pay;
  81.     money=pay-sum;
  82.     if(money==0)
  83.     {
  84.         cout<<"您付的錢剛剛好, 謝謝惠顧!"<<endl;
  85.     }else if(money<0)
  86.     {
  87.         cout<<"您付的錢不夠, 還差"<<-money<<"元!"<<endl;
  88.         goto pay;   
  89.     }else
  90.     {
  91.         cout<<endl<<"找您"<<money<<"元!"<<endl;
  92.         if(money>=500)
  93.         {
  94.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  95.             money%=500;                 
  96.         }
  97.         if(money>=100)
  98.         {
  99.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  100.             money%=100;              
  101.         }
  102.         if(money>=50)
  103.         {
  104.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  105.             money%=50;              
  106.         }
  107.         if(money>=10)
  108.         {
  109.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  110.             money%=10;              
  111.         }
  112.         if(money>=5)
  113.         {
  114.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  115.             money%=5;              
  116.         }
  117.         if(money>=1)
  118.         {
  119.             cout<<"一元硬幣"<<money<<"枚"<<endl;              
  120.         }      
  121.     }
  122.     cout<<endl;
  123.   system ("pause");   
  124.   return 0;   
  125. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     start:
  7.     string name[7]={"乒乓球","棒球  ","網球  ","足球  ",
  8.                     "海灘球","躲避球","籃球  "};
  9.     int price[7]={50,70,80,200,150,300,600};
  10.     int qty[7]={0,0,0,0,0,0,0};
  11.     int p,q,sum=0;
  12.     int option;
  13.     int pay,money;
  14.     cout<<"☆★☆ 超帥球店 ☆★☆"<<endl<<endl;
  15.     cout<<"[商品價目表]"<<endl;
  16.     for(int i=0; i<=6; i++)
  17.     {
  18.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;     
  19.     }
  20.     cout<<"(8)結帳"<<endl;
  21.     cout<<"優惠方案:消費滿一千元,送足球一顆!!"<<endl<<endl;
  22.     re:
  23.     cout<<"請輸入商品代碼: ";
  24.     cin>>p;
  25.     if(p>=1 && p<=7)
  26.     {
  27.         cout<<"數量: ";
  28.         cin>>q;
  29.         if(q>0)
  30.         {
  31.             sum=sum+price[p-1]*q;
  32.             qty[p-1]+=q;
  33.             goto re;
  34.         }
  35.         else
  36.         {
  37.             cout<<"輸入錯誤!"<<endl;
  38.             goto re;  
  39.         }
  40.      }
  41.      else if(p==8)
  42.      {
  43.          goto checkout;      
  44.      }
  45.      else
  46.      {
  47.          cout<<"輸入錯誤!"<<endl;
  48.          goto re;     
  49.      }
  50.     checkout:
  51.     cout<<endl<<"[購物清單]";  
  52.     cout<<endl<<"=========================="<<endl;
  53.     for(int i=0; i<=6; i++)
  54.     {
  55.         if(qty[i]!=0)
  56.            cout<<name[i]<<"\t"<<price[i]<<"元 X "<<qty[i]<<"個"<<endl;
  57.     }
  58.     cout<<"=========================="<<endl;
  59.     cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
  60.     if(sum>=1000)
  61.        cout<<"由於您消費一千元以上,送足球一顆"<<endl<<endl;
  62.     cout<<"1-正確無誤   2-重新選購"<<endl;
  63.     cin>>option;
  64.     if(option==1)
  65.     {
  66.          goto pay;
  67.     }else if(option==2)
  68.     {
  69.          system("cls");   
  70.          goto start;  
  71.     }else
  72.     {
  73.          cout<<"輸入錯誤!"<<endl;
  74.          goto start;
  75.     }
  76.     pay:
  77.     cout<<endl<<"請付帳: ";
  78.     cin>>pay;
  79.     money=pay-sum;
  80.     if(money==0)
  81.     {
  82.         cout<<"您付的錢剛剛好, 謝謝惠顧!"<<endl;
  83.     }else if(money<0)
  84.     {
  85.         cout<<"您付的錢不夠, 還差"<<-money<<"元!"<<endl;
  86.         goto pay;   
  87.     }else
  88.     {
  89.         cout<<endl<<"找您"<<money<<"元!"<<endl<<endl;
  90.         if(money>=500)
  91.         {
  92.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  93.             money%=500;           
  94.         }
  95.         if(money>=100)
  96.         {
  97.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  98.             money%=100;              
  99.         }
  100.         if(money>=50)
  101.         {
  102.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  103.             money%=50;              
  104.         }
  105.         if(money>=10)
  106.         {
  107.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  108.             money%=10;              
  109.         }
  110.         if(money>=5)
  111.         {
  112.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  113.             money%=5;              
  114.         }
  115.         if(money>=1)
  116.         {
  117.             cout<<"一元硬幣"<<money<<"枚"<<endl;              
  118.         }      
  119.     }
  120.     cout<<endl;
  121.     system("pause");   
  122.     return 0;
  123. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     start:
  7.    cout<<"***Legend's Sports Store***"<<endl;
  8.   cout<<"The Price LIST"<<endl;
  9.   string name[7]={"Rose4                 ",
  10.                  "NIKE Ambassader  ",
  11.                  "JORDAN FLIGHT    ",
  12.                  "ADIfast         ",
  13.                  "adizero crazy light  ",
  14.                  "NIKE hyperdunk 2013  ",
  15.                  "ADIZERO CRAZY QUICK"  };
  16.   int price[7]={4500,
  17.                 3950,
  18.                 2400,
  19.                 2780,
  20.                 2950,
  21.                 2495,
  22.                 2154};
  23.   int qty[7]={0,0,0,0,0,0,0};
  24.      int p,q,sum=0,a,option,money,pay;            
  25.     for(int i=0; i<=6; i++)
  26.     {
  27.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;     
  28.     }
  29.     cout<<"(8)結帳"<<endl<<endl;
  30.     cout<<"消費滿5000,送您城市球衣乙件"<<endl;
  31.     re:
  32.     cout<<"請輸入商品代碼: ";
  33.     cin>>p;
  34.     if(p>=1 && p<=7)
  35.     {
  36.         cout<<"數量: ";
  37.         cin>>q;
  38.         if(q>0)
  39.         {
  40.             sum=sum+price[p-1]*q;
  41.             qty[p-1]=qty[p-1]+q;
  42.             goto re;
  43.         }else
  44.         {
  45.             cout<<"輸入錯誤!"<<endl;
  46.             goto re;  
  47.         }
  48.     }else if(p==8)
  49.     {
  50.         goto checkout;      
  51.     }else
  52.     {
  53.         cout<<"輸入錯誤!"<<endl;
  54.         goto re;     
  55.     }
  56.     checkout:   
  57.     cout<<"購物清單"<<endl;
  58.     cout<<"------------------"<<endl;
  59.     for(int i=0; i<=6; i++)
  60.     {
  61.           if(qty[i]!=0)  
  62.         cout<<name[i]<<"\t"<<price[i]<<"*"<<qty[i]<<"個"<<endl;     
  63.     }
  64.     cout<<"------------------"<<endl;
  65.      cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
  66.      if(sum>=5000)
  67.      cout<<"免費獲得城市球衣一件,加100元升級聖誕特別版喔!!"<<endl;
  68.      cout<<"1-正確無誤 2-重新選購";
  69.      cin>>option;
  70.      if(option==1)
  71.      {
  72.       goto pay;           
  73.      }else if(option==2)
  74.      {
  75.       system("cls");
  76.       goto start;     
  77.      }else
  78.     {
  79.          cout<<"輸入錯誤!"<<endl;
  80.          goto start;
  81.     }
  82.     pay:
  83.     cout<<endl<<"請付帳: ";
  84.     cin>>pay;
  85.     money=pay-sum;
  86.     if(money==0)
  87.     {
  88.         cout<<"您付的錢剛剛好, 謝謝惠顧!"<<endl;
  89.     }else if(money<0)
  90.     {
  91.         cout<<"您付的錢不夠, 還差"<<-money<<"元!"<<endl;
  92.         goto pay;   
  93.     }else
  94.     {
  95.         cout<<endl<<"找您"<<money<<"元!"<<endl;
  96.         if(money>=500)
  97.         {
  98.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  99.             money%=500;    //money=money%500;              
  100.         }
  101.         if(money>=100)
  102.         {
  103.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  104.             money%=100;              
  105.         }
  106.         if(money>=50)
  107.         {
  108.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  109.             money%=50;              
  110.         }
  111.         if(money>=10)
  112.         {
  113.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  114.             money%=10;              
  115.         }
  116.         if(money>=5)
  117.         {
  118.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  119.             money%=5;              
  120.         }
  121.         if(money>=1)
  122.         {
  123.             cout<<"一元硬幣"<<money<<"枚"<<endl;              
  124.         }      
  125.     }
  126.    
  127.     system("pause");
  128.     return 0;
  129. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     start:
  7.     string name[7]={"戰地風雲3","戰地風雲4","絕勝時刻9","絕勝時刻10",
  8.                     "極地戰嚎3","末日之戰3","武裝行動3"};                  
  9.     int price[7]={399,599,299,200,499,459,399};     
  10.     int qty[7]={0,0,0,0,0,0,0};         
  11.     int p,q,sum=0;     
  12.     int option;         
  13.     int pay,money;     
  14.     cout<<"@@@無敵電玩店@@@"<<endl<<endl;
  15.     cout<<"消費滿5000就送<<戰地風雲3重返卡肯>>資料片!!!!!"<<endl;
  16.     cout<<"[商品價目表]"<<endl;
  17.     for(int i=0; i<=6; i++)
  18.      {
  19.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;     
  20.     }
  21.     cout<<"(8)結帳"<<endl<<endl;
  22.     re:
  23.     cout<<"請輸入商品代碼: ";
  24.     cin>>p;
  25.     if(p>=1 && p<=7)
  26.     {
  27.         cout<<"數量: ";
  28.         cin>>q;
  29.         if(q>0)
  30.         {
  31.             sum+=price[p-1]*q;   
  32.             qty[p-1]+=q;        
  33.             goto re;
  34.         }else
  35.         {
  36.             cout<<"輸入錯誤!"<<endl;
  37.             goto re;  
  38.         }
  39.     }else if(p==8)
  40.     {
  41.         goto checkout;      
  42.     }else
  43.     {
  44.         cout<<"輸入錯誤!"<<endl;
  45.         goto re;     
  46.     }
  47.     checkout:
  48.     cout<<endl<<"[購物清單]"<<endl;
  49.     cout<<"======================="<<endl;
  50.     for(int i=0; i<=6; i++)
  51.     {
  52.         if(qty[i]!=0)     
  53.             cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;      
  54.     }
  55.     cout<<"======================"<<endl;
  56.     cout<<"總共 "<<sum<<"元!"<<endl<<endl;
  57.     cout<<"1-正確無誤 2-重新選購  ";
  58.     cin>>option;
  59.     if(option==1)
  60.     {
  61.          goto pay;
  62.     }else if(option==2)
  63.     {
  64.          system("cls");      
  65.          goto start;  
  66.     }else
  67.     {
  68.          cout<<"輸入錯誤!"<<endl;
  69.          goto start;
  70.     }
  71.     pay:
  72.     cout<<endl<<"請付帳: ";
  73.     cin>>pay;
  74.     if(pay>=5000)
  75.     {
  76.           cout<<"恭喜!!消費滿5000送<<戰地風雲3重返卡肯>>資料片!";      
  77.     }else
  78.     {
  79.           cout<<"消費未滿5000";
  80.     }
  81.     money=pay-sum;
  82.     if(money==0)
  83.     {
  84.         cout<<"您付的錢剛剛好!"<<endl;
  85.     }else if(money<0)
  86.     {
  87.         cout<<"您付的錢不夠, 還差"<<-money<<"元!"<<endl;
  88.         goto pay;   
  89.     }else
  90.     {
  91.         cout<<endl<<"找您"<<money<<"元!"<<endl;
  92.         if(money>=500)
  93.         {
  94.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  95.             money%=500;    //money=money%500;              
  96.         }
  97.         if(money>=100)
  98.         {
  99.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  100.             money%=100;              
  101.         }
  102.         if(money>=50)
  103.         {
  104.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  105.             money%=50;              
  106.         }
  107.         if(money>=10)
  108.         {
  109.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  110.             money%=10;              
  111.         }
  112.         if(money>=5)
  113.         {
  114.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  115.             money%=5;              
  116.         }
  117.         if(money>=1)
  118.         {
  119.             cout<<"一元硬幣"<<money<<"枚"<<endl;              
  120.         }      
  121.     }
  122.     cout<<endl;
  123.     system("pause");         
  124.     return 0;
  125. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    start:
  7.    string name[7]={"冬瓜茶  ","蘋果冰沙","檸檬愛玉","珍珠奶茶","阿華田  ","多多綠茶","紅茶    "};
  8.    int price[7]={15,30,25,25,25,25,15};
  9.    int qty[7]={0,0,0,0,0,0,0};           
  10.     int p,q,sum=0,fsum;      
  11.     int option;         
  12.     int pay,money;      
  13.     cout<<"☆★☆ 智能玩具店 ☆★☆"<<endl<<endl;
  14.     cout<<"[商品價目表]"<<endl;
  15.     for(int i=0; i<=6; i++)
  16.      {
  17.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;     
  18.     }
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     cout<<"[優惠方案]  消費滿一百,享九折優惠。"<<endl<<endl;
  21.     re:
  22.     cout<<"請輸入商品代碼: ";
  23.     cin>>p;
  24.     if(p>=1 && p<=7)
  25.     {
  26.         cout<<"數量: ";
  27.         cin>>q;
  28.         if(q>0)
  29.         {
  30.             sum+=price[p-1]*q;   
  31.             qty[p-1]+=q;         
  32.             goto re;
  33.         }else
  34.         {
  35.             cout<<"輸入錯誤!"<<endl;
  36.             goto re;  
  37.         }
  38.     }else if(p==8)
  39.     {
  40.         goto checkout;      
  41.     }else
  42.     {
  43.         cout<<"輸入錯誤!"<<endl;
  44.         goto re;     
  45.     }
  46.     checkout:
  47.     cout<<endl<<"[購物清單]"<<endl;
  48.     cout<<"-----------------------------"<<endl;
  49.     for(int i=0; i<=6; i++)
  50.     {
  51.         if(qty[i]!=0)   
  52.             cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;      
  53.     }
  54.     cout<<"-----------------------------"<<endl;
  55.     cout<<"總共 "<<sum<<"元!"<<endl<<endl;
  56.     if(sum>=100)
  57.     {
  58.         fsum=sum*0.9;
  59.         cout<<"由於您的消費金額滿一百,您可以享九折優惠。"<<endl;
  60.         cout<<"您只需付"<<fsum<<"元,現省"<<sum-fsum<<"元!"<<endl<<endl;
  61.         sum=fsum;         
  62.     }
  63.     cout<<"1-正確無誤 2-重新選購  ";
  64.     cout<<"請輸入您的選擇:";
  65.     cin>>option;
  66.     if(option==1)
  67.     {
  68.          goto pay;
  69.     }else if(option==2)
  70.     {
  71.          system("cls");      
  72.          goto start;  
  73.     }else
  74.     {
  75.          cout<<"輸入錯誤!"<<endl;
  76.          goto start;
  77.     }
  78.     pay:
  79.     cout<<endl<<"請輸入您要付的錢: ";
  80.     cin>>pay;
  81.     money=pay-sum;
  82.     if(money==0)
  83.     {
  84.         cout<<"您付的錢剛剛好, 謝謝惠顧!"<<endl;
  85.     }else if(money<0)
  86.     {
  87.         cout<<"您付的錢不夠, 還差"<<-money<<"元!"<<endl;
  88.         goto pay;   
  89.     }else
  90.     {
  91.         
  92.         cout<<endl<<"找您"<<money<<"元!"<<endl;
  93.         if(money>=2000)
  94.         {
  95.             cout<<"二元鈔票"<<money/2000<<"張"<<endl;
  96.             money%=2000;            
  97.         }
  98.         if(money>=1000)
  99.         {
  100.             cout<<"一千元鈔票"<<money/1000<<"張"<<endl;
  101.             money%=1000;            
  102.         }
  103.         if(money>=500)
  104.         {
  105.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  106.             money%=500;           
  107.         }
  108.         if(money>=100)
  109.         {
  110.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  111.             money%=100;              
  112.         }
  113.         if(money>=50)
  114.         {
  115.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  116.             money%=50;              
  117.         }
  118.         if(money>=10)
  119.         {
  120.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  121.             money%=10;              
  122.         }
  123.         if(money>=5)
  124.         {
  125.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  126.             money%=5;              
  127.         }
  128.         if(money>=1)
  129.         {
  130.             cout<<"一元硬幣"<<money<<"枚"<<endl;              
  131.         }      
  132.     }
  133.     cout<<endl;
  134.     system("pause");         
  135.     return 0;
  136. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     start:
  7.     string name[7]={"遙控飛機",
  8.                     "水槍    ",
  9.                     "玩偶    ",
  10.                     "足球    ",
  11.                     "拼圖    ",
  12.                     "籃球    ",
  13.                     "玩具車"};
  14.     int price[7]={5000,6500,7000,6550,8888,3000,7500,};
  15.     int qty[7]={0,0,0,0,0,0,0};
  16.     int p,q,sum=0,option,pay,money,a;
  17.     cout<<"***貴死人玩具店***"<<endl<<endl;
  18.     cout<<"[商品價目表]"<<endl;
  19.     for(int i=0;i<=6;i++)
  20.     {
  21.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;   
  22.     }
  23.     cout<<"(8)結帳"<<endl<<endl;
  24.     cout<<"[優惠方案]消費滿一萬享9折優惠!!!"<<endl<<endl;
  25.     re:
  26.     cout<<"請輸入商品代碼:"<<endl;
  27.     cin>>p;
  28.     if(p>=1 && p<=7)
  29.     {   
  30.          cout<<"請輸入數量:"<<endl;
  31.          cin>>q;
  32.          if(q>0)
  33.          {
  34.              sum+=price[p-1]*q;
  35.              qty[p-1]+=q;
  36.              goto re;
  37.          }
  38.          else  
  39.          {
  40.              cout<<"輸入錯誤!"<<endl;
  41.              goto re;   
  42.          }
  43.     }
  44.     else if(p==8)
  45.     {
  46.          goto checkout;   
  47.     }
  48.     else
  49.     {
  50.          cout<<"輸入錯誤!"<<endl;
  51.          goto re;
  52.     }
  53.     checkout:
  54.     cout<<"[購物清單]"<<endl;
  55.     cout<<"==========================="<<endl;
  56.     for(int i=0;i<=6;i++)
  57.     {
  58.         if(qty[i]!=0)
  59.             cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元*"<<qty[i]<<"個"<<endl;   
  60.     }
  61.     cout<<"==========================="<<endl;         
  62.     cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
  63.     if(sum<10000)
  64.     {
  65.         cout<<"您還差"<<10000-sum<<"元就可享9折優惠,需重新選購嗎?"<<endl;
  66.         cout<<"1-要 2-不用了,謝謝"<<endl;
  67.         cin>>a;
  68.         if(a==1)
  69.         {
  70.             system("cls");
  71.             goto start;   
  72.         }
  73.     }
  74.     else if(sum>=10000)
  75.     {
  76.         cout<<"由於消費滿一萬,所以可享9折優惠"<<endl;
  77.         cout<<"您只要付"<<sum*0.9<<"元!,省下了"<<sum*0.1<<"元喔!!"<<endl;
  78.         sum*=0.9;              
  79.     }               
  80.     cout<<endl<<"1-正確無誤 2-重新選購"<<endl;
  81.     cin>>option;
  82.     if(option==1)
  83.     {
  84.         goto pay;
  85.     }
  86.     else if(option==2)
  87.     {
  88.         system("cls");
  89.         goto start;     
  90.     }
  91.     else
  92.     {
  93.         cout<<"輸入錯誤!"<<endl;
  94.         goto start;   
  95.     }
  96.     pay:
  97.     cout<<"請付帳:";
  98.     cin>>pay;
  99.     money=pay-sum;
  100.      if(money<0)
  101.     {
  102.         cout<<"您付的錢還不夠,還差"<<-money<<"元!"<<endl;
  103.         goto pay;        
  104.     }
  105.     else if(money==0)
  106.     {
  107.         cout<<"你付的錢剛剛好,請慢走"<<endl;
  108.     }
  109.     else         
  110.     {
  111.         cout<<"找您"<<money<<"元!"<<endl;
  112.             if(money>=500)
  113.             {
  114.                 cout<<"500元鈔票"<<money/500<<"張"<<endl;
  115.                 money%=500;
  116.             }
  117.             if(money>=100)
  118.             {
  119.                 cout<<"100元鈔票"<<money/100<<"張"<<endl;
  120.                 money%=100;
  121.             }
  122.             if(money>=50)
  123.             {
  124.                 cout<<"50元硬幣"<<money/50<<"枚"<<endl;
  125.                 money%=50;
  126.             }
  127.             if(money>=10)
  128.             {
  129.                 cout<<"10元硬幣"<<money/10<<"枚"<<endl;
  130.                 money%=10;
  131.             }
  132.             if(money>=5)
  133.             {
  134.                 cout<<"5元硬幣"<<money/5<<"枚"<<endl;
  135.                 money%=5;
  136.             }
  137.             if(money>=1)
  138.             {
  139.                 cout<<"1元硬幣"<<money<<"枚"<<endl;
  140.                 money=money%1;
  141.             }
  142.     }                                 
  143.     system("pause");
  144.     return 0;
  145. }
複製代碼

TOP

本帖最後由 周雍程 於 2014-3-8 15:21 編輯
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     start:
  7.     string name[7]={"[稀有物種]黃金玫瑰",
  8.                     "食人花              ",
  9.                     "幽靈草              ",
  10.                     "瘋樹                ",
  11.                     "魔鬼藤蔓           ",
  12.                     "含兇草              ",
  13.                     "搖頭樹              "};
  14.     int price[7]={700000000,1598,2960,1800,4050,3999,6540};
  15.     int qty[7]={0,0,0,0,0,0,0};
  16.     int p, q, sum=0;
  17.     int option;
  18.     int pay, money;
  19.     cout<<"***  special植物專賣店  ***"<<endl<<endl;
  20.    
  21.     for(int i=0; i<=6; i++)
  22.     {
  23.       cout<<"<"<<i+1<<">"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  24.     }
  25.     cout<<"<8>結帳"<<endl<<endl<<endl;
  26.     cout<<"[優惠方案]"<<endl;
  27.     cout<<"消費滿5000元立即贈送無敵種植肥料1公頓!!"<<endl;
  28.     re:
  29.     cout<<"請輸入商品代碼: "<<endl;
  30.     cin>>p;
  31.     if(p>=1 && p<=7)
  32.     {
  33.         cout<<"數量: ";
  34.         cin>>q;
  35.         if(q>0)
  36.         {
  37.             sum=sum+price[p-1]*q;
  38.             qty[p-1]=qty[p-1]+q;
  39.             goto re;
  40.         }
  41.     }
  42.     else if(p==8)
  43.     {
  44.         goto checkout;      
  45.     }
  46.     else
  47.     {
  48.         cout<<"輸入錯誤!"<<endl;
  49.         goto re;     
  50.     }
  51.     checkout:
  52.     cout<<endl<<"購物清單"<<endl;
  53.     cout<<"------------------"<<endl;
  54.     for(int i=0; i<=6; i++)
  55.     {
  56.       if(qty[i]!=0)      
  57.       cout<<name[i]<<"\t"<<price[i]<<" * "<<qty[i]<<"個"<<endl;
  58.     }
  59.     cout<<"------------------"<<endl;
  60.     cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
  61.     if(sum>=5000)
  62.     {
  63.        cout<<"恭喜你獲得無敵種植肥料1公頓!!"<<endl;      
  64.     }
  65.     else
  66.     {
  67.        cout<<"由於未滿5000元,無法獲得無敵種植肥料"<<endl;      
  68.     }
  69.     cout<<"1-正確無誤 2-重新選購  ";
  70.     cin>>option;
  71.     if(option==1)
  72.     {
  73.          goto pay;
  74.     }else if(option==2)
  75.     {
  76.          system("cls");      
  77.          goto start;  
  78.     }else
  79.     {
  80.          cout<<"輸入錯誤!"<<endl;
  81.          goto start;
  82.     }
  83.     pay:
  84.     cout<<endl<<"請付帳: ";
  85.     cin>>pay;
  86.     money=pay-sum;
  87.     if(money==0)
  88.     {
  89.         cout<<"您付的錢剛剛好, 謝謝惠顧!"<<endl;
  90.     }else if(money<0)
  91.     {
  92.         cout<<"您付的錢不夠, 還差"<<-money<<"元!"<<endl;
  93.         goto pay;   
  94.     }else
  95.     {
  96.         cout<<endl<<"找您"<<money<<"元!"<<endl;
  97.         if(money>=500)
  98.         {
  99.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  100.             money%=500;                 
  101.         }
  102.         if(money>=100)
  103.         {
  104.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  105.             money%=100;              
  106.         }
  107.         if(money>=50)
  108.         {
  109.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  110.             money%=50;              
  111.         }
  112.         if(money>=10)
  113.         {
  114.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  115.             money%=10;              
  116.         }
  117.         if(money>=5)
  118.         {
  119.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  120.             money%=5;              
  121.         }
  122.         if(money>=1)
  123.         {
  124.             cout<<"一元硬幣"<<money<<"枚"<<endl;              
  125.         }      
  126.     }
  127.     cout<<endl;
  128.     system("pause");         
  129.     return 0;
  130. }
複製代碼

TOP

返回列表