本帖最後由 莊旻叡 於 2017-5-20 08:48 編輯
- #include<cstdlib>
- #include<iostream>
- using namespace std;
- int main()
- {
- int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i,j;
- cout<<"商品金額";
- cin>>a;
- cout<<"所付金額";
- cin>>b;
- h=b-a;
- if(h>=500)
- {
- c=h/500;
- h=h%500;
- }
- if(h>=100&&h<500)
- {
- d=h/100;
- h=h%100;
- }
- if(h>=50&&h<100)
- {
- e=h/50;
- h=h%50;
- }
- if(h>=10&&h<50)
- {
- f=h/10;
- h=h%10;
- }
- if(h>=5&&h<10)
- {
- i=h/5;
- h=h%5;
- }
- if(h>=1&&h<5)
- {
- f=h/1;
- h=h%1;
- }
- cout << "總共需找客人" << b-a << endl;
- cout << "500元鈔票" << c << "張" << endl;
- cout << "100元鈔票" << d << "張" << endl;
- cout << "50元硬幣" << e << "枚" << endl;
- cout << "10元硬幣" << f << "枚" << endl;
- cout << "5元硬幣" << i << "枚" << endl;
- cout << "1元硬幣" << j << "枚" << endl;
- system("pause");
- return 0;
- }
複製代碼 |