返回列表 發帖
本帖最後由 湯郡一 於 2019-3-9 11:47 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.         int z,f,sum=0;
  8.         int option,pay,money;
  9.     string x[]={"菠蘿麵包      ","小餐\包(六入)  ","巧克力熱壓吐司","紅豆麵包     ","桂圓麵包     ","培根玉米三明治","北歐圓法(四入)  "};
  10.     int y[]={35,50,45,30,55,65,45};
  11.     int count[]={0,0,0,0,0,0,0};
  12.     cout<<"左營可口麵包店"<<endl<<endl;
  13.     cout<<"{麵包價目表]"<<endl;
  14.    
  15.      for(int i=0;i<7;i++)
  16.     {
  17.         cout<<"("<<i+1<<")"<<x[i]<<"\t"<<y[i]<<"元"<<endl;
  18.     }
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     while(true)
  21.     {
  22.         cout<<"請輸入商品代碼: ";        
  23.         cin>>z;
  24.         if(z<1 || z>8)
  25.         {
  26.                cout<<"輸入錯誤"<<endl;
  27.                continue;
  28.         }
  29.         if(z==8)
  30.           break;
  31.         cout<<"數量: ";
  32.         cin>>f;
  33.         if(f<1 || f>999)
  34.         {
  35.                cout<<"超過"<<endl;
  36.                continue;
  37.         }
  38.         count[z-1]+=f;
  39.         sum+=y[z-1]*f;                    
  40.     }
  41.     cout<<"[購物清單]"<<endl;
  42.     cout<<"---------------------"<<endl;
  43.     for(int i=0;i<7;i++)
  44.     {
  45.             if (count[i]!=0 )
  46.                 cout<<x[i]<<"\t"<<y[i]<<"*"<<count[i]<<endl;   
  47.     }
  48.     cout<<"---------------------"<<endl;
  49.     cout<<endl<<"共"<<sum<<"元!"<<endl;
  50.     re2:
  51.     cout<<"1=正確無誤  2=重新選購";
  52.     cin>>option;
  53.     if(option==1)
  54.     {
  55.       re3:
  56.       cout<<"請付帳:";
  57.       cin>>pay;
  58.       money=pay-sum;
  59.       if(money<0)
  60.       {
  61.          cout<<"錢不夠,還差"<<-money<<"元"<<endl;        
  62.          goto re3;        
  63.       }else if(money==0)
  64.       {
  65.         cout<<"銘謝惠顧!!"<<endl;   
  66.       }else
  67.       {
  68.            cout<<"找您"<<money<<"元"<<endl;
  69.            if(money>=500)
  70.            {
  71.                 cout<<"500元"<<money/500<<"張"<<endl;
  72.                 money%=500;
  73.            }
  74.             if(money>=100)
  75.            {
  76.                 cout<<"100元"<<money/100<<"張"<<endl;
  77.                 money%=100;
  78.            }
  79.            if(money>=50)
  80.            {
  81.                 cout<<"50元"<<money/50<<"個"<<endl;
  82.                 money%=50;
  83.            }
  84.            if(money>=10)
  85.            {
  86.                 cout<<"10元"<<money/10<<"個"<<endl;
  87.                 money%=10;
  88.            }
  89.            if(money>=5)
  90.            {
  91.                 cout<<"5元"<<money/5<<"個"<<endl;
  92.                 money%=5;
  93.            }
  94.            if(money>=1)
  95.            {
  96.                 cout<<"1元"<<money/1<<"個"<<endl;
  97.                 money%=1;
  98.            }
  99.            
  100.       }  
  101.     }else if(option==2)
  102.     {
  103.           goto re;
  104.     }else
  105.     {
  106.          cout<<"輸入錯誤"<<endl;
  107.          goto re2;
  108.     }
  109.    
  110.     system("pause");
  111.     return 0;            
  112. }
複製代碼

TOP

返回列表