Advertisement
Guest User

change

a guest
Sep 26th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <bits/stdc++.h> // to include all needed libraries
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. iostream::sync_with_stdio(false); //to increase speed of cout
  8.  
  9. int x; cin >> x;
  10.  
  11. int coins[4] = {25, 10, 5, 1};
  12. string names[4] = {"quarter", "dime", "nickel", "cent"};
  13.  
  14. int counter[4];
  15. int rmn = x;
  16. for (int i = 0; i < 4; i++) {
  17. counter[i] = rmn / coins[i];
  18. rmn = rmn % coins[i];
  19. }
  20. bool isPrinted = false;
  21. cout << x << " cents requires";
  22. for(int i = 0; i < 4; i++) {
  23.  
  24. if (counter[i] != 0) {
  25.  
  26. cout << " " << counter[i] << " " << names[i] << ((counter[i] > 1) ? "s" : "");
  27. isPrinted = true;
  28.  
  29. }
  30. if (isPrinted and i != 3) {
  31. if (counter[i+1] > 0) {
  32. cout << ",";
  33. isPrinted = false;
  34. }
  35.  
  36. }
  37.  
  38. if (i == 3) {
  39. cout << '.' << "\n";
  40. }
  41.  
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement