Advertisement
Garey

Plamena Recursive

Feb 26th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. size_t count_of_coins(double, double, size_t &);
  6.  
  7. int main() {
  8.  
  9.     double price, coin;
  10.     size_t count = 0;
  11.  
  12.     cout << "Enter price: ";
  13.     cin >> price;
  14.     cout << "Enter coin: ";
  15.     cin >> coin;
  16.  
  17.     cout << count_of_coins(price, coin, count) << endl;
  18.  
  19.     return 0;
  20. }
  21.  
  22. size_t count_of_coins(double price, double coin, size_t &count) {
  23.     if (price <= 0.0)
  24.         return 0;
  25.     else {
  26.         count++;
  27.         count_of_coins(price - coin, coin, count);
  28.         //cout << price << " | " << count << endl; // Debug
  29.  
  30.     }
  31.  
  32.     return count;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement