返回列表 發帖
  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

返回列表