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