標題:
智慧找零系統
[打印本頁]
作者:
tonyh
時間:
2018-7-13 16:23
標題:
智慧找零系統
設計一智慧找零系統, 使用者可輸入商品價格與客人付了多少錢, 電腦回應需找多少錢, 並顯示細節.
譬如: 若有一230元的商品, 客人付了1000元, 則電腦回應
總共需找客人770元
500元鈔票1張
100元鈔票2張
50元硬幣1枚
10元硬幣2枚
本帖隱藏的內容需要回復才可以瀏覽
作者:
古昇暘
時間:
2018-7-20 16:45
本帖最後由 古昇暘 於 2018-7-20 17:16 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int price,pay,money;
cout<<" ***Money calculator*** "<<endl<<endl;
cout<<" Please enter the price: ";
cin>>price;
cout<<" How much money did the customer pay: ";
cin>>pay;
money=pay-price;
cout<<endl<<" You have to give back the customer "<<money<<" dollars"<<endl<<endl;
if (money>=500)
{
cout<<" Five hundred dollar note "<<money/500<<" notes "<<endl;
money%=500;
}
if (money>=100)
{
cout<<" One hundred dollar note "<<money/100<<"notes"<<endl;
money%=100;
}
if (money>=50)
{
cout<<" Fifty dollar note "<<money/50<<"notes"<<endl;
money%=50;
}
if (money>=10)
{
cout<<" Ten dollar note "<<money/10<<"notes"<<endl;
money%=10;
}
if (money>=5)
{
cout<<" Five dollar note "<<money/5<<"notes"<<endl;
money%=5;
}
if (money>=1)
{
cout<<" One dollar note "<<money/1<<"notes"<<endl;
money%=1;
}
if(money>0)
cout<<" One cent "<<money<<" cents "<<endl;
cout<<endl;
system("pause");
goto re;
return 0;
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2