Advertisement
TheC0zen0ne

Change

Jun 20th, 2011
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. //      int totalCoins[4];    coins.cpp
  2. //      
  3. //      Copyright 2011 Public Domain
  4.  
  5.  
  6. #include <iostream>
  7. #include <stdio.h>
  8. using namespace std;
  9. int main(int argc, char** argv)
  10. {
  11.     int value;
  12.     //delete cout + cin if you would like it to be non interactive.
  13.     cout << "Enter value:";
  14.     cin >> value;
  15.     int coins[4] = {25,10,5,1};
  16.     int totalCoins[4] = {0,0,0,0};
  17.     int moneyRemaining = value;
  18.     for (int i = 0;moneyRemaining != 0;i++) {
  19.         //how many coins can fit in the value
  20.         totalCoins[i] = moneyRemaining / coins[i];
  21.         //how much money remains
  22.         moneyRemaining = moneyRemaining % coins[i];
  23.  
  24.     }
  25.     cout << "Amount of Money:$" << value * .01 << endl;
  26.     cout << "Change to make value\n----------------------------" << endl;
  27.     cout << "Quarters:" << totalCoins[0] << endl;
  28.     cout << "Dimes:" << totalCoins[1] << endl;
  29.     cout << "Nickels:" << totalCoins[2] << endl;
  30.     cout << "Pennies:" << totalCoins[3] << endl;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement