- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int price,pay,money;
- cout<<"***智慧找零系統***"<<endl<<endl;
- cout<<"請輸入商品價格: ";
- cin>>price;
- cout<<"請輸入客人付的錢: ";
- cin>>pay;
- money=pay-price;
- cout<<"你應該找給客人"<<money<<"元"<<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>=1)
- {
- cout<<"一元硬幣"<<money/1<<"枚"<<endl;
- money=money%1;
- }
- system("pause");
- return 0;
- }
複製代碼 |