Advertisement
frares

ATM

Aug 12th, 2022
965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. // Write a software for an ATM machine in C/C++
  2.  
  3. // We have an unlimited amount of 1,5,10,50,100,200,500 RON banknotes
  4. // Write a program that computes the minimum number of banknotes needed to give
  5. // the customer the cash requested
  6.  
  7. // Input: 750
  8. // Output 500 1 200 1 50 1
  9. // Explanation: 750 RON is given out as 1* 500RON + 1*200RON + 1*50RON = 750
  10. // Input: 235
  11. // Output 200 1 10 3 5 1
  12. // Explanation: 235 RON is given out as 1 * 200RON + 3*10 RON + 1*5RON = 235
  13. // Input: 9999
  14. // Output 500 119 200 2 50 1 10 4 5 1 1 4
  15.  
  16. //Example:
  17.  
  18. #include <stdio.h>
  19.  
  20. const char name[] = "Francisco José Alonso Ares"; // Please enter your name here
  21. //const char name[] = "Ion Popescu"; // as such
  22.  
  23. void withdraw(int n) {
  24. // this function computes and prints the result
  25. // Your code goes here
  26.     int stock[7] = { 500, 200, 100, 50, 10, 5, 1 };
  27.     int given[7] = {   0,   0,   0,  0,  0, 0, 0 };
  28.     int val = n;
  29.     int idx = 0;
  30.    
  31.     while (val > 0) {
  32.         while (val >= stock[idx]) {
  33.             val -= stock[idx];
  34.             given[idx]+=1;
  35.         }
  36.         if (given[idx] > 0) {
  37.             printf ("%d %d ", stock[idx] , given[idx]);
  38.         }
  39.         idx++;
  40.     }
  41. }
  42.    
  43. int main() {   
  44.     withdraw(750); // prints out 500 1 200 1 150 1
  45.     return 0;
  46. }
  47.  
  48.  
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement