Board logo

標題: [隨堂練習] 智慧找零系統 [打印本頁]

作者: 周政輝    時間: 2017-5-13 09:46     標題: [隨堂練習] 智慧找零系統

設計一智慧找零系統, 使用者可輸入商品價格與客人付了多少錢, 電腦回應需找多少錢, 並顯示細節.
譬如: 若有一230元的商品, 客人付了1000元, 則電腦回應
        總共需找客人770元
        500元鈔票1張
        100元鈔票2張
        50元硬幣1枚
        10元硬幣2枚
  1.    cout << " 總共需找客人" << pay-price << endl;
  2.      cout << "500元鈔票"   <<  num << "張" << endl;
  3.      cout << "100元鈔票"   <<  num2 << "張" << endl;
  4.      cout << "50元硬幣"   <<  num3 << "枚" << endl;
  5.      cout << "10元硬幣"   <<  num4 << "枚" << endl;
複製代碼

作者: 莊旻叡    時間: 2017-5-13 09:56

本帖最後由 莊旻叡 於 2017-5-20 08:48 編輯
  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i,j;
  7.     cout<<"商品金額";
  8.     cin>>a;
  9.     cout<<"所付金額";
  10.     cin>>b;
  11.     h=b-a;
  12.     if(h>=500)
  13.     {
  14.        c=h/500;
  15.        h=h%500;            
  16.     }
  17.     if(h>=100&&h<500)
  18.     {
  19.        d=h/100;
  20.        h=h%100;            
  21.     }
  22.     if(h>=50&&h<100)
  23.     {
  24.        e=h/50;
  25.        h=h%50;            
  26.     }
  27.     if(h>=10&&h<50)
  28.     {
  29.        f=h/10;
  30.        h=h%10;            
  31.     }
  32.     if(h>=5&&h<10)
  33.     {
  34.        i=h/5;
  35.        h=h%5;           
  36.     }
  37.     if(h>=1&&h<5)
  38.     {
  39.        f=h/1;
  40.        h=h%1;            
  41.     }
  42.     cout << "總共需找客人" << b-a << endl;
  43.     cout << "500元鈔票"   <<  c << "張" << endl;
  44.     cout << "100元鈔票"   <<  d << "張" << endl;
  45.     cout << "50元硬幣"   <<  e << "枚" << endl;
  46.     cout << "10元硬幣"   <<  f << "枚" << endl;
  47.     cout << "5元硬幣"   <<  i << "枚" << endl;
  48.     cout << "1元硬幣"   <<  j << "枚" << endl;
  49.     system("pause");
  50.     return 0;   
  51. }
複製代碼

作者: 高品溫    時間: 2017-5-13 10:14

  1. #include<cstdlib>
  2. using namespace std;
  3. int main()
  4. {     
  5.      
  6.      int pay=0;
  7.      int price=0;
  8.      int Flash=0;
  9.      int Q=0;
  10.      int W=0;
  11.      int E=0;
  12.      int R=0;
  13.      cout << "商品價格:"<< endl;
  14.      cin>>price;
  15.      cout << "支付的錢:"<< endl;
  16.      cin>>pay;
  17.      Flash=pay-price;
  18.      if(Flash>=500)
  19.       {
  20.         Q=Flash/500;
  21.         int TP=Flash%500;
  22.         Flash=TP;
  23.       }
  24.       if(Flash>=100)
  25.       {
  26.         W=Flash/100;
  27.         int TP=Flash%100;
  28.         Flash=TP;
  29.       }
  30.       if(Flash>=50)
  31.       {
  32.         E=Flash/50;
  33.         int TP=Flash%50;
  34.         Flash=TP;
  35.       }
  36.       if(Flash>=10)
  37.       {  
  38.         R=Flash/10;
  39.         int TP=Flash%10;
  40.         Flash=TP;
  41.       }
  42.      cout << " 總共需找客人" << pay-price << endl;
  43.      cout << "500元鈔票"   <<  Q << "張" << endl;
  44.      cout << "100元鈔票"   <<  W << "張" << endl;
  45.      cout << "50元硬幣"   <<  E << "枚" << endl;
  46.      cout << "10元硬幣"   <<  R << "枚" << endl;
  47.    
  48.      system("pause");
  49.      return 0;
  50. }
複製代碼

作者: 高睿辰    時間: 2017-5-13 10:28

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a,b,c,;
  7.     int num,num1,num2,num3;
  8.     cout<<"請輸入商品價格"<<endl;
  9.     cin>>a;
  10.     cout<<"請輸入支付費用"<<endl;
  11.     cin>>b;
  12.     c=b-a;
  13.    
  14.    
  15.     if(c>=500)
  16.     {
  17.              num=c/500;
  18.              int i=c%500;
  19.              c=i;
  20.     }
  21.     if(c>=100&&c<500)
  22.     {
  23.              num1=c/100;
  24.              int i=c%100;
  25.              c=i;
  26.     }
  27.     if(c>=50&&c<100)
  28.     {
  29.              num2=c/50;
  30.              int i=c%50;
  31.              c=i;
  32.     }
  33.     if(c>=10&&c<50)
  34.     {
  35.              num3=c/10;
  36.              int i=c%10;
  37.              c=i;
  38.     }
  39.      cout << " 總共需找客人" << b-a << endl;
  40.      cout << "500元鈔票"   <<  num << "張" << endl;
  41.      cout << "100元鈔票"   <<  num1 << "張" << endl;
  42.      cout << "50元硬幣"   <<  num2 << "枚" << endl;
  43.      cout << "10元硬幣"   <<  num3 << "枚" << endl;
  44.         system("pause");
  45.         return 0;
  46. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2