返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[]={"四人套房        ","兩人套房        ","七人小木屋        ","孤單一人房        ","百人總統房        ","安靈病房        ","太平間地下房        ","跟泳鱔一夜情套房"};
  7.     int qty[]={0,0,0,0,0,0,0,0};
  8.     int price[]={10000,5000,50000,4444,10,1744,55,10000};
  9.     int h, q, pay, money,sum=0,a;
  10.     cout<<"以諾豪華九星級飯店"<<endl;
  11.     cout<<"[飯店房間價目表]"<<endl;
  12.     cout<<"(1)四人套房\t10000元"<<endl;
  13.     cout<<"(2)兩人套房\t5000元"<<endl;
  14.     cout<<"(3)七人小木屋\t50000元"<<endl;
  15.     cout<<"(4)孤單一人房\t4444元"<<endl;
  16.     cout<<"(5)百人總統房\t10元"<<endl;
  17.     cout<<"(6)安靈病房\t1744元"<<endl;
  18.     cout<<"(7)太平間地下房\t55元"<<endl;
  19.     cout<<"(8)跟詠鱔一夜情套房\t1元"<<endl;
  20.     cout<<"[付費說明]"<<endl;
  21.     cout<<"把要住的房間代號輸入後,再輸入要買幾間"<<endl;
  22.     cout<<"購買完請輸入9前往結帳"<<endl;
  23.     start:
  24.     cout<<"請輸入商品代碼: ";
  25.     cin>>h;
  26.     if(h==9)
  27.     {
  28.     goto checkout;
  29.             }
  30.     else if(h>=1 && h<=8)
  31.     {
  32.          cout<<"請輸入購買數量: ";
  33.          cin>>q;
  34.             if(q>0)
  35.             {
  36.               sum=sum+price[h-1]*q;
  37.               qty[h-1]=q;
  38.               goto start;
  39.             }
  40.     else
  41.         {
  42.              cout<<"輸入錯誤!"<<endl;
  43.              goto start;     
  44.         }      
  45.     }        
  46.     else
  47.     {
  48.         cout<<"什麼年紀了還會輸入錯誤!!"<<endl;
  49.         goto start;
  50.         }
  51.     checkout:
  52.     cout<<"購物清單"<<endl;
  53.     cout<<"$$$$$$$$$$$$$$$$$$$$"<<endl;  
  54.     for(int i=0;i<=7;i++)
  55.     {
  56.           if(qty[i]!=0)  
  57.           cout<<name[i]<<"\t"<<price[i]<<"元 *"<<qty[i]<<"個"<<endl;
  58.             }
  59.     cout<<"$$$$$$$$$$$$$$$$$$$$"<<endl;
  60.     cout<<"1.前去結帳 2-重新選購"<<endl;
  61.     cin>>a;
  62.     if(a==1)
  63.     {
  64.            goto checkout2;
  65.            }
  66.     else if(a==2)
  67.     {
  68.            goto  start;  
  69.                }
  70.     else
  71.     {
  72.            cout<<"什麼年紀了還會輸入錯誤!!"<<endl;  
  73.         }
  74.     checkout2:
  75.     cout<<"\t\t總共是"<<sum<<"元"<<endl;
  76.     cout<<"請輸入客人付了多少錢: ";
  77.     cin>>pay;
  78.     money=pay-sum;
  79.     if(money==0)
  80.     {
  81.         cout<<"錢剛剛好! 請慢走!"<<endl;
  82.     }
  83.     if(money<0)
  84.     {
  85.         cout<<"錢不夠! 還少"<<-money<<endl;                  
  86.     }
  87.     if(money>0)
  88.     {
  89.          cout<<"總共需要找客人"<<money<<"元"<<endl;   
  90.          if(money>=500)
  91.          {
  92.             cout<<"500元鈔票"<<money/500<<"張"<<endl;
  93.             money=money%500;
  94.          }
  95.          if(money>=100)
  96.          {
  97.             cout<<"100元鈔票"<<money/100<<"張"<<endl;
  98.             money=money%100;
  99.          }
  100.          if(money>=50)
  101.          {
  102.             cout<<"50元硬幣"<<money/50<<"枚"<<endl;
  103.             money=money%50;
  104.          }
  105.          if(money>=10)
  106.          {
  107.             cout<<"10元硬幣"<<money/10<<"枚"<<endl;
  108.             money=money%10;
  109.          }
  110.     }     
  111. system("pause");
  112. return 0;
  113. }     
複製代碼

TOP

返回列表