Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h> // to include all needed libraries
- using namespace std;
- int main()
- {
- iostream::sync_with_stdio(false); //to increase speed of cout
- int x; cin >> x;
- int coins[4] = {25, 10, 5, 1};
- string names[4] = {"quarter", "dime", "nickel", "cent"};
- int counter[4];
- int rmn = x;
- for (int i = 0; i < 4; i++) {
- counter[i] = rmn / coins[i];
- rmn = rmn % coins[i];
- }
- bool isPrinted = false;
- cout << x << " cents requires";
- for(int i = 0; i < 4; i++) {
- if (counter[i] != 0) {
- cout << " " << counter[i] << " " << names[i] << ((counter[i] > 1) ? "s" : "");
- isPrinted = true;
- }
- if (isPrinted and i != 3) {
- if (counter[i+1] > 0) {
- cout << ",";
- isPrinted = false;
- }
- }
- if (i == 3) {
- cout << '.' << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement