Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // int totalCoins[4]; coins.cpp
- //
- // Copyright 2011 Public Domain
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- int main(int argc, char** argv)
- {
- int value;
- //delete cout + cin if you would like it to be non interactive.
- cout << "Enter value:";
- cin >> value;
- int coins[4] = {25,10,5,1};
- int totalCoins[4] = {0,0,0,0};
- int moneyRemaining = value;
- for (int i = 0;moneyRemaining != 0;i++) {
- //how many coins can fit in the value
- totalCoins[i] = moneyRemaining / coins[i];
- //how much money remains
- moneyRemaining = moneyRemaining % coins[i];
- }
- cout << "Amount of Money:$" << value * .01 << endl;
- cout << "Change to make value\n----------------------------" << endl;
- cout << "Quarters:" << totalCoins[0] << endl;
- cout << "Dimes:" << totalCoins[1] << endl;
- cout << "Nickels:" << totalCoins[2] << endl;
- cout << "Pennies:" << totalCoins[3] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement