本帖最後由 陳品肇 於 2021-12-4 10:38 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int price, money;
- cout<<"*** 智慧找零系統 ***"<<endl;
- cout<<endl;
- cout<<"請輸入商品價格:";
- cin>>price;
- cout<<"客人付了多少錢:";
- cin>>money;
- // 空白
- cout<<endl;
- // 我把money-price 指派給tmp
- int tmp =money-price;
- 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 >=1)
- {
-
- cout<<"一元硬幣"<<tmp<<"枚"<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |