本帖最後由 連翊恩 於 2022-4-16 17:13 編輯
[code#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
system("cls");
int price,pay,money;
cout<<"*** 智慧找零系統 ***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>price;
cout<<"客人付了多少錢: ";
cin>>pay;
money=pay-price;
{
if(price==pay)
{
cout<<"剛剛好,銘謝惠顧"<<endl;
}
if(price<pay)
{
cout<<"錢還不夠,還差"<<money<<"元"<<endl;
}
if(pay>1000)
{
cout<<"錢太多,全送我吧"<<endl;
}
else{
cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
if(money>=500)
cout<<"五百元鈔票"<<money/500<<"張"<<endl;
money%=500;
}
if(money>=100)
{
cout<<"一百元鈔票"<<money/100<<"張"<<endl;
money%=100;
}
if(money>=50)
{
cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
money%=50;
}
if(money>=10)
{
cout<<"十元硬幣"<<money/10<<"枚"<<endl;
money%=10;
}
if(money>=5)
{
cout<<"五元硬幣"<<money/5<<"枚"<<endl;
money%=5;
}
if(money>0)
{ cout<<"一元硬幣"<<money<<"枚"<<endl;
cout<<endl;
}
}
system("pause");
return 0;
} |