- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int a,b=0,c,d;
- re:
- cout<<"請輸入要買的商品(1)蘋果18元(2)芒果56元(3)西瓜250元(4)結帳: ";
- cin>>a;
- switch(a)
- {
- case 1:
- b=b+18;
- cout<<"目前: "<<b<<"元\n\n";
- break;
- case 2:
- b=b+56;
- cout<<"目前: "<<b<<"元\n\n";
- break;
- case 3:
- b=b+250;
- cout<<"目前: "<<b<<"元\n\n";
- break;
- case 4:
- cout<<"目前: "<<b<<"元\n";
- cout<<"付款: ";
- cin>>c;
- d=c-b;
- cout<<"需找"<<d<<"元\n\n";
- if(d/500>0)
- {
- cout<<"500元"<<d/500<<"張\n";
- d=d%500;
- }
- if(d/100>0)
- {
- cout<<"100元"<<d/100<<"張\n";
- d=d%100;
- }
- if(d/50>0)
- {
- cout<<"50元"<<d/50<<"枚\n";
- d=d%50;
- }
- if(d/10>0)
- {
- cout<<"10元"<<d/10<<"枚\n";
- d=d%10;
- }
- if(d/5>0)
- {
- cout<<"5元"<<d/5<<"枚\n";
- d=d%5;
- }
- if(d>0)
- {
- cout<<"1元"<<"枚\n";
- }
- b=0;
- cout<<endl;
- break;
-
- }
-
-
- goto re;
-
- system("pause");
- return 0;
- }
複製代碼 |