- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- int price,pay,money;
- cout<<"*** 智慧找零系統 ***"<<endl<<endl;
- cout<<"請輸入商品價格: ";
- cin>>price;
- cout<<"客人付了多少錢: ";
- cin>>pay;
- money=pay-price;
- cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
- if(money>=500)
- {
- cout<<"五百元鈔票"<<money/500<<"張"<<endl;
- money%=500; //money=money%500;
- }
- if(money>=100)
- {
- cout<<"一百元鈔票"<<money/100<<"張"<<endl;
- money%=100;
- }
- if(money>=50)
- {
- cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
- money%=50;
- }
- if(money>=10)
- {
- cout<<"十元硬幣"<<money/10<<"枚"<<endl;
- money%=10;
- }
- if(money>=5)
- {
- cout<<"五元硬幣"<<money/5<<"枚"<<endl;
- money%=5;
- }
- if(money>0)
- cout<<"一元硬幣"<<money<<"枚"<<endl;
- cout<<endl;
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |