Advertisement
kolioi

Coins (w/ array)

Apr 27th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     float money;
  8.     cin >> money;
  9.  
  10.     int amount = money * 100;
  11.  
  12.     int count = 0;
  13.     int nominals[] { 200, 100, 50, 20, 10, 5, 2, 1 };
  14.  
  15.     for (int i = 0; amount; ++i)
  16.     {
  17.         int num = amount / nominals[i];
  18.         if (num)
  19.         {
  20.             count += num;
  21.             amount -= num * nominals[i];
  22.         }
  23.     }
  24.  
  25.     cout << count << '\n';
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement