1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
using namespace std;
int bills, total;
int hundreds = 0;
int fifties = 0;
int twenties = 0;
int tens = 0;
int fives = 0;
int ones = 0;
//function prototype
void change(int total, int hundreds, int fifties, int twenties, int tens, int fives, int ones);
int main()
{
//ask user for the amount of money
cout << "Enter the total amount of money as an integer: ";
cin >> total;
//call the change function
change(total, hundreds, fifties, twenties, tens, fives, ones);
//output the number of bills
cout << "Number of hundred dollar bills: " << hundreds << endl;
cout << "Number of fifty dollar bills: " << fifties << endl;
cout << "Number of twenty dollar bills: " << twenties << endl;
cout << "Number of ten dollar bills: " << tens << endl;
cout << "Number of five dollar bills: " << fives << endl;
cout << "Number of one dollar bills: " << ones << endl;
return 0;
}
//change function
void change(int total, int hundreds, int fifties, int twenties, int tens, int fives, int ones)
{
while (total >= 100)
{
total -= 100;
hundreds += 1;
}
while (total >= 50)
{
total -= 50;
fifties += 1;
}
while (total >= 20)
{
total -= 20;
twenties += 1;
}
while (total >= 10)
{
total -= 10;
tens += 1;
}
while (total >= 5)
{
total -= 5;
fives += 1;
}
while (total >= 1)
{
total -= 1;
ones += 1;
}
}
|