- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main (){
- int x,y,z;
- cout<<"***智慧找零系統***"<<endl;
- re:
- cout<<"請輸入商品價格";
- cin>>x;
- cout<<"客人付了多少?";
- cin>>y;
- z=y-x;
- cout<<"需要找客人"<<z<<"元"<<endl;
- {
- if(z>=500)
- cout<<"500元鈔票"<<z/500<<"張"<<endl;
- z%=500;
- if (z<500&&z>=100)
- cout<<"100元鈔票"<<z/500<<"張"<<endl;
- z%=100;
- if(z>=50&&z<100)
- cout<<"50元硬幣"<<z/50<<"個"<<endl;
- z%=50;
- if(z>=10&&z<50)
- cout<<"10元硬幣"<<z/10<<"個"<<endl;
- z%=10;
- if(z>=5&&z<10)
- cout<<"5元硬幣"<<z/5<<"個"<<endl;
- z%=5;
- if(z>=1&&z<5)
- cout<<"1元硬幣"<<z/1<<"個"<<endl;
- z%=1;
- }
- cout<<endl;
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |