本帖最後由 高湘庭 於 2024-6-29 15:26 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main(){
- int money,pay,price;
- re:
- system("cls");
- cout<<"***智慧找零系統***"<<endl;
- cout<<"商品價格:";
- cin>>price;
- cout<<"客人付了多少:";
- cin>>pay;
- money=pay-price;
- cout<<"需找客人"<<money<<"元"<<endl;
- if(pay<0)
- {
- goto re;
- }
- {
- if(money==0){
- cout<<"剛剛好!銘謝惠顧"<<endl;}
- if(money<0){
- cout<<"錢不夠,需要補"<<-(money)<<"元"<<endl;
- system("pause");
- goto re;}
- if(money>1000){
- cout<<"錢太多,給我好了"<<endl;}
- if(money>=500&&money<1000){
- cout<<"500元鈔票"<<money/500<<"張"<<endl;
- money%=500;
- }
- if(money>=500&&money<1000){
- cout<<"500元鈔票"<<money/500<<"張"<<endl;
- money%=500;
- }
- if(money>=500&&money<1000){
- cout<<"500元鈔票"<<money/500<<"張"<<endl;
- money%=500;
- }
- if(money>=100&&money<500){
- cout<<"100元鈔票"<<money/100<<"張"<<endl;
- money%=100;
- }
- if(money>=50&&money<100){
- cout<<"50元硬幣"<<money/50<<"個"<<endl;
- money%=50;
- }
- if(money>=10&&money<50){
- cout<<"10元硬幣"<<money/10<<"個"<<endl;
- money%=10;
- }
- if(money>=5&&money<10){
- cout<<"5元硬幣"<<money/5<<"個"<<endl;
- money%=5;
- }
- else {
- cout<<"1元硬幣"<<money<<"個"<<endl;
- money%=1;
- }
- }
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |