返回列表 發帖
本帖最後由 莊旻叡 於 2017-5-20 08:48 編輯
  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i,j;
  7.     cout<<"商品金額";
  8.     cin>>a;
  9.     cout<<"所付金額";
  10.     cin>>b;
  11.     h=b-a;
  12.     if(h>=500)
  13.     {
  14.        c=h/500;
  15.        h=h%500;            
  16.     }
  17.     if(h>=100&&h<500)
  18.     {
  19.        d=h/100;
  20.        h=h%100;            
  21.     }
  22.     if(h>=50&&h<100)
  23.     {
  24.        e=h/50;
  25.        h=h%50;            
  26.     }
  27.     if(h>=10&&h<50)
  28.     {
  29.        f=h/10;
  30.        h=h%10;            
  31.     }
  32.     if(h>=5&&h<10)
  33.     {
  34.        i=h/5;
  35.        h=h%5;           
  36.     }
  37.     if(h>=1&&h<5)
  38.     {
  39.        f=h/1;
  40.        h=h%1;            
  41.     }
  42.     cout << "總共需找客人" << b-a << endl;
  43.     cout << "500元鈔票"   <<  c << "張" << endl;
  44.     cout << "100元鈔票"   <<  d << "張" << endl;
  45.     cout << "50元硬幣"   <<  e << "枚" << endl;
  46.     cout << "10元硬幣"   <<  f << "枚" << endl;
  47.     cout << "5元硬幣"   <<  i << "枚" << endl;
  48.     cout << "1元硬幣"   <<  j << "枚" << endl;
  49.     system("pause");
  50.     return 0;   
  51. }
複製代碼

TOP

返回列表