- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- cout<<"*** 智慧找零系統 ***"<<endl;
- re:
- int a,b;
- cout<<"商品價格:";
- cin>>a;
- cout<<"客人付了多少錢:";
- cin>>b;
- int c=b-a;
- if(c==0)
- {
- cout<<"剛剛好"<<endl;
- cout<<endl;
- goto re;
- }
- else if(c<0)
- {
- cout<<"錢不夠,還差"<<-c<<"元"<<endl;
- cout<<endl;
- goto re;
- }
- else if(c>10000)
- {
- cout<<"錢太多?"<<endl;
- cout<<endl;
- goto re;
- }
- else
- cout<<endl;
- cout<<"需找給客人"<<c<<"元"<<endl;
- cout<<endl;
- cout<<"1000元鈔票找"<<c/1000<<"張"<<endl;
- c=c%1000;
- cout<<"500元鈔票找"<<c/500<<"張"<<endl;
- c=c%500;
- cout<<"100元鈔票找"<<c/100<<"張"<<endl;
- c=c%100;
- cout<<"50元銅板找"<<c/50<<"個"<<endl;
- c=c%50;
- cout<<"10元銅板找"<<c/10<<"個"<<endl;
- c=c%10;
- cout<<"5元銅板找"<<c/5<<"個"<<endl;
- c=c%5;
- cout<<"1元銅板找"<<c/1<<"個"<<endl;
- cout<<endl;
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |