- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- int price,money,pay;
- cout<<"***智慧找零系統***"<<endl;
- cout<<"請輸入商品價錢"<<endl;
- cin>>price;
- cout<<"客人付了多少?"<<endl;
- cin>>pay;
- money=pay-price;
- if(price<0)
- goto re;
- else if(pay<0)
- goto re;
- else if(money==0)
- cout<<"剛剛好!銘謝惠顧"<<endl;
- else if(money<0)
- cout<<"錢不夠喔還差"<<-money<<"元"<<endl;
- else if(money>0)
- cout<<"須找客人"<<money<<"元"<<endl;
- if(money>=1000)
- cout<<"錢太多都給我好了"<<endl;
- if(money>500&&money<1000)
- {
- cout<<"500元紙鈔"<<money/500<<"張"<<endl;
- money%=500;
- }
- if(money<500)
- {
- cout<<"100元紙鈔"<<money/100<<"張"<<endl;
- money%=100;
- }
- if(money<100)
- {
- cout<<"50元硬幣"<<money/50<<"個"<<endl;
- money%=50;
- }
- if(money<50)
- {
- cout<<"10元硬幣"<<money/10<<"個"<<endl;
- money%=10;
- }
- if(money<10)
- {
- cout<<"5元硬幣"<<money/5<<"個"<<endl;
- money%=5;
- }
- if(money<5)
- {
- cout<<"1元硬幣"<<money/1<<"個"<<endl;
- }
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |