- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v;
- cout<<"***智慧找零系統***"<<endl<<endl;
- cout<<"請輸入商品價格: ";
- cin>>a;
- cout<<"客人付了多少錢: ";
- cin>>b;
- cout<<"須找客人多少錢: "<<b-a<<endl;
- c=b-a;
- d=c/1000;
- e=d*1000;
- f=c-e;
- g=f/500;
- h=g*500;
- i=f-h;
- j=i/100;
- k=j*100;
- l=i-k;
- m=l/50;
- n=m*50;
- o=l-n;
- p=o/10;
- q=p*10;
- s=o-q;
- t=s/5;
- u=t*5;
- v=s-u;
- if(b>a)
- {
- if(c/1000>0)
- cout<<"一千元"<<c/1000<<"張"<<endl;
- else
- cout<<endl;
- if(f/500>0)
- cout<<"五百元"<<f/500<<"張"<<endl;
- else
- cout<<endl;
- if(i/100>0)
- cout<<"一百元"<<i/100<<"張"<<endl;
- else
- cout<<endl;
- if(l/50>0)
- cout<<"五十元"<<l/50<<"枚"<<endl;
- else
- cout<<endl;
- if(o/10>0)
- cout<<"十元"<<o/10<<"枚"<<endl;
- else
- cout<<endl;
- if(s/5>0)
- cout<<"五元"<<s/5<<"枚"<<endl;
- else
- cout<<endl;
- if(v/1>0)
- cout<<"一元"<<v/1<<"枚"<<endl;
- else
- cout<<endl;
- }
- else if(a==b)
- cout<<"剛剛好! 銘謝惠顧!"<<endl;
- else if(a>b)
- cout<<"還差"<<a-b<<"元"<<endl;
- else if(c>10000)
- cout<<"錢太多? 全部送我吧!"<<endl;
- else
- cout<<endl;
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |