本帖最後由 陳品肇 於 2018-11-24 10:13 編輯
設計一個更聰明的智慧找零系統, 包括客人付的錢不足, 剛好, 或任何可能發生的狀況(超出商品價格的10倍).
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
-
- int money, price, tmp;
- cout<<"**智慧找零系統**"<<endl;
- cout<<"請輸入商品價格:";
- cin>> price;
- cout<<"客人付了多少錢:";
- cin>> money;
- cout<<endl;
- tmp = money - price;
-
-
- if(price == money)
- {
- cout<<"剛剛好!銘謝惠顧~~"<<endl;
- }else if(price > money)
- {
- cout<<"錢不夠哦!~~還差"<<price-money<<"元"<<endl;
- }else if(money >= 1000 )
- {
- cout<<"錢太多? 全部送我吧!"<<endl;
- }else
- {
- cout<<"需找客人"<<tmp<<"元"<<endl<<endl;
- if(tmp>=500)
- {
- cout<<"五百元鈔票"<<tmp/500<<"張"<<endl;
- tmp =tmp%500;
- }
-
- if(tmp>=100)
- {
- cout<<"一百元鈔票"<<tmp/100<<"張"<<endl;
- tmp =tmp%100;
- }
-
- if(tmp>=50)
- {
- cout<<"五十元硬幣"<<tmp/50<<"枚"<<endl;
- tmp =tmp%50;
- }
-
- if(tmp>=10)
- {
- cout<<"十元硬幣"<<tmp/10<<"枚"<<endl;
- tmp =tmp%10;
- }
-
- if(tmp>0)
- {
- cout<<"一元硬幣"<<tmp<<"枚"<<endl;
- }
- }
- system("pause");
- return 0;
- }
複製代碼 |