Ritam_C

URI Bank notes and coins

Dec 28th, 2020 (edited)
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     double notes[] = {100.00, 50.00, 20.00, 10.00, 5.00, 2.00};
  7.     double coins[] = {100, 50, 25, 10, 5, 1};
  8.    
  9.     double money;
  10.     cin >> money;
  11.    
  12.     int whole = money;
  13.            
  14.     cout << "NOTAS:" << endl;
  15.     for(int i = 0; i < sizeof(notes)/(sizeof(double)); i++){
  16.         int n = whole/(int)(notes[i]);
  17.         cout << n << " nota(s) de R$ " << fixed << setprecision(2) << notes[i] << endl;
  18.         whole = whole%(int)notes[i];
  19.     }
  20.  
  21.     int decimal = whole*100 + ((money*100) - ((int)money)*100);
  22.    
  23.     cout << "MOEDAS:" << endl;
  24.     for(int i = 0; i < sizeof(coins)/sizeof(double); i++){
  25.         int n = (int)decimal/(int)coins[i];
  26.         cout << n << " moeda(s) de R$ " << fixed << setprecision(2) << coins[i]/100.00 << endl;
  27.         decimal = decimal%(int)coins[i];
  28.     }
  29.    
  30.     return 0;
  31. }
Add Comment
Please, Sign In to add comment