- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int a,b,c,d;
- cout<<"***智慧找零系統***"<<endl;
- cout<<"請輸入商品價格:";
- cin>>a;
- cout<<"客人付了多少錢:";
- cin>>b;
- c=b-a;
- d=b-a;
- if(a==b)
- {
- cout<<"剛剛好!銘謝惠顧!!"<<endl;
- }
-
- else if(b<a && c<10)
- {
- cout<<"錢不夠喔! ,還差"<<b-a<<"元"<<endl;
- }
- else if(b>a)
- {
-
- cout<<"要找:"<<d<<"元"<<endl;
- if(d>=500)
- {
- cout<<"500:"<<d/500<<"張"<<endl;
- d=d%500;
- }
- if(d>=100)
- {
- cout<<"100:"<<d/100<<"張"<<endl;
- d=d%100;
- }if(d>=50)
- {
- cout<<"50:"<<d/50<<"枚"<<endl;
- d=d%50;
- }if(d>=10)
- {
- cout<<"10:"<<d/10<<"枚"<<endl;
- d=d%10;
- }if(d>=5)
- {
- cout<<"5:"<<d/5<<"枚"<<endl;
- d=d%5;
- }
- if(d>=1)
- {
- cout<<"1:"<<d<<"枚"<<endl;
- }
-
- }
- else
- {
- cout<<"錯誤"<<b-a<<endl;
- }
-
- system("pause");
- return 0;
- }
複製代碼 |