- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int price, pay, money;
- cout<<"***智慧找零系統***"<<endl;
- cout<<"請輸入商品價格: ";
- cin>>price;
- cout<<"請輸入客人付了多少錢: ";
- cin>>pay;
- money=pay-price;
- cout<<"總共需找客人"<<money<<"元"<<endl;
- if(money>=500)
- {
- cout<<"500元鈔票"<<money/500<<"張"<<endl;
- money=money%500;
- }
- if(money>=100)
- {
- cout<<"100元鈔票"<<money/100<<"張"<<endl;
- money=money%100;
- }
- if(money>=50)
- {
- cout<<"50元硬幣"<<money/50<<"枚"<<endl;
- money=money%50;
- }
- if(money>=10)
- {
- cout<<"10元硬幣"<<money/10<<"枚"<<endl;
- money=money%10;
- }
- if(money>=5)
- {
- cout<<"5元硬幣"<<money/5<<"枚"<<endl;
- money=money%5;
- }
- if(money>=1)
- {
- cout<<"1元硬幣"<<money<<"枚"<<endl;
- }
- if(price>pay)
- {
- cout<<"客人,你的錢不夠,留下來洗碗吧!"<<endl;
- }else
- if(pay==price)
- {
- cout<<"錢剛好!"<<endl;
- } else
- if(price>2000 && pay>price)
- {
- cout<<"沒錢還買這麼貴的東西,你打算怎麼付?"<<endl;
- }
- system("pause");
- return 0;
- }
-
複製代碼 |