返回列表 發帖
  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;
  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<<"\t\t總共是"<<sum<<"元"<<endl;
  61.     cout<<"請輸入客人付了多少錢: ";
  62.     cin>>pay;
  63.     money=pay-sum;
  64.     if(money==0)
  65.     {
  66.         cout<<"錢剛剛好! 請慢走!"<<endl;
  67.     }
  68.     if(money<0)
  69.     {
  70.         cout<<"錢不夠! 還少"<<-money<<endl;                  
  71.     }
  72.     if(money>0)
  73.     {
  74.          cout<<"總共需要找客人"<<money<<"元";   
  75.          if(money>=500)
  76.          {
  77.             cout<<"500元鈔票"<<money/500<<"張"<<endl;
  78.             money=money%500;
  79.          }
  80.          if(money>=100)
  81.          {
  82.             cout<<"100元鈔票"<<money/100<<"張"<<endl;
  83.             money=money%100;
  84.          }
  85.          if(money>=50)
  86.          {
  87.             cout<<"50元硬幣"<<money/50<<"枚"<<endl;
  88.             money=money%50;
  89.          }
  90.          if(money>=10)
  91.          {
  92.             cout<<"10元硬幣"<<money/10<<"枚"<<endl;
  93.             money=money%10;
  94.          }
  95.     }     
  96. system("pause");
  97. return 0;
  98. }     
複製代碼

TOP

返回列表