返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     system("cls");        
  8.     int sum=0;
  9.     int x,y,o,buy,corn;  
  10.     string s[]={"珍珠奶茶","茉莉綠茶","泡沫紅茶","菊花茶","多多綠茶","梅子可樂","檸檬愛玉"};
  11.     int m[]={50,35,20,30,35,25,45};
  12.     int z[]={0,0,0,0,0,0,0};
  13.     cout<<"☆★☆清薪飲料店☆★☆"<<endl<<endl;
  14.     cout<<"[商品價目表]"<<endl;
  15.     for(int i=0;i<7;i++)
  16.     {
  17.             cout<<"("<<i+1<<")"<<s[i]<<"\t"<<m[i]<<"元"<<endl;
  18.     }
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     while(true)
  21.     {      
  22.     cout<<"請輸入商品代碼: ";
  23.     cin>>x;
  24.     if(x==8)  
  25.       break;
  26.     cout<<"數量: ";
  27.     cin>>y;
  28.     z[x-1]+=y;
  29.     sum+=m[x-1]*y;                          
  30.     }cout<<endl;
  31.     cout<<"[購物清單]"<<endl;
  32.     cout<<"---------------------"<<endl;
  33.     for(int i=0;i<7;i++)
  34.     {
  35.             if(z[i]!=0)
  36.             cout<<s[i]<<"\t"<<z[i]<<"元 * "<<z[i]<<"個"<<endl;
  37.     }   
  38.     cout<<"---------------------";
  39.    
  40.     cout<<endl<<"共"<<sum<<"元!"<<endl<<endl;
  41.     cout<<"1=正確無誤  2=重新選購   ";
  42.     cin>>o;
  43.     if(o==1)
  44.     {
  45.       cout<<"請付帳:";
  46.       cin>>buy;
  47.       corn=buy-sum;
  48.       if(corn<0)
  49.       {
  50.        cout<<"錢不夠喔,還差"<<sum-buy<<"元"<<endl;         
  51.       }else if(corn==0)
  52.       {
  53.             cout<<"剛剛好,謝謝惠顧"<<endl;
  54.       }else
  55.       {
  56.          cout<<"找您"<<corn<<"元"<<endl;
  57.          if(corn>=500)
  58.          {
  59.              cout<<"五百元鈔票"<<corn/500<<"張"<<endl;
  60.              corn=corn%500;
  61.          }
  62.          if(corn>=100)
  63.          {
  64.          cout<<"一百元鈔票"<<corn/100<<"張"<<endl;
  65.          corn=corn%100;
  66.          }
  67.          if(corn>=10)
  68.          {
  69.          cout<<"五十元硬幣"<<corn/50<<"枚"<<endl;
  70.          corn=corn%50;
  71.          }
  72.           if(corn>=10)
  73.          {
  74.          cout<<"十元硬幣"<<corn/10<<"枚"<<endl;
  75.          corn=corn%10;
  76.          }
  77.          if(corn>=1)
  78.          {
  79.          cout<<"一元硬幣"<<corn/1<<"枚"<<endl;
  80.         
  81.          }
  82.       }
  83.             
  84.     }else
  85.     {
  86.        goto re;  
  87.     }                        
  88.     system("pause");
  89.     return 0;   
  90. }
複製代碼

TOP

返回列表