- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
-
- int a, b,c;
- cout<<"請輸入商品價格:";
- cin>>a;
- cout<<"你付多少:";
- cin>>b;
- c=b-a;
-
- if(c<0){
- cout<<"你少付"<<-(b-a)<<"元"<<endl;
- }
- else if (c==0){
- cout<<"付款金額剛好,無需找錢。"<<endl;
- }
- else {
- cout<<"總共需找客人:"<<c<<"元"<<endl;
- if(c>=500){
- cout<<"500元鈔票"<<c/500<<"張"<<endl;
- }
- c -= c/500*500;
- if(c>=100){
- cout<<"100元鈔票"<<c/100<<"張"<<endl;
- }
- c -= c/100*100;
- if(c>=50){
- cout<<"50元硬幣"<<c/50<<"枚"<<endl;
- }
- c -= c/50*50;
- if(c>=10){
- cout<<"10元硬幣"<<c/10<<"枚"<<endl;
- }
- }
-
-
- system ("pause");
- return 0;
- }
複製代碼 |