返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. cout<<"*** 智慧找零系統 ***"<<endl;
  7. re:
  8.     int a,b;
  9.     cout<<"商品價格:";
  10.     cin>>a;
  11.     cout<<"客人付了多少錢:";
  12.     cin>>b;
  13.     int c=b-a;
  14.     if(c==0)
  15.     {
  16.         cout<<"剛剛好"<<endl;
  17.         cout<<endl;
  18.         goto re;
  19.     }
  20.     else if(c<0)
  21.     {
  22.         cout<<"錢不夠,還差"<<-c<<"元"<<endl;
  23.         cout<<endl;
  24.         goto re;
  25.     }
  26.     else if(c>10000)
  27.     {
  28.         cout<<"錢太多?"<<endl;
  29.         cout<<endl;
  30.         goto re;
  31.     }
  32.     else
  33.     cout<<endl;
  34.     cout<<"需找給客人"<<c<<"元"<<endl;
  35.     cout<<endl;
  36.     cout<<"1000元鈔票找"<<c/1000<<"張"<<endl;
  37.     c=c%1000;
  38.     cout<<"500元鈔票找"<<c/500<<"張"<<endl;
  39.     c=c%500;
  40.     cout<<"100元鈔票找"<<c/100<<"張"<<endl;
  41.     c=c%100;
  42.     cout<<"50元銅板找"<<c/50<<"個"<<endl;
  43.     c=c%50;
  44.     cout<<"10元銅板找"<<c/10<<"個"<<endl;
  45.     c=c%10;
  46.     cout<<"5元銅板找"<<c/5<<"個"<<endl;
  47.     c=c%5;
  48.     cout<<"1元銅板找"<<c/1<<"個"<<endl;
  49.     cout<<endl;
  50.     goto re;
  51.     system("pause");
  52.     return 0;
  53. }
複製代碼

TOP

返回列表