Bill Program

Write a set of detailed, step-by-step instructions in English to calculate the fewest number of dollar bills needed to pay a bill of amount TOTAL. For example, if TOTAL is $97, the bills would consist of one $50 bill, two $20 bills, one $5 bill, and two $1 bills. (For this exercise, assume that only $100, $50, $20, $10, $5, and $1 bills are available

*Note* We will add a $2 bill in addition to the one given in the original problem and to simplify matters, you will all work with a sum of $283.00

Can any1 Help Me please, just need the steps…
make an array with the available bills and just try to fit the biggest inside the total.

97 -> 50 is biggest fit.
47-> 20 is biggest fit.
27 -> 20 is biggest fit.
7 -> 5 is biggest fit.
2 -> 1 is biggest fit.
1 -> 1 is biggest fit.
0 -> done.
^ the array might seem a bit complex, considering how basic this problem is.

the array he's talking about would be {100, 50, 20, 10, 5 ,2, 1}

lets assume int total = 97;
basically in c++ division of integers ignores decimals, so 97/50 = 1
to access the remainder you use modulus 97%50 = 47

this in my opinion would be better cause it doesn't ask the types of bills, so you can just count the result of the integer division

1
2
3
4
5
6
7
int total = 97;
int count = 0;
int dollarValues [7] = {100, 50, 20, 10, 5, 2, 1};
for(int i = 0; i < 7; i++){
      count += total/dollarValues[i];
      total %= dollarValues[i];
}



Last edited on
complex? it is just a way to store the numbers....
you actually wrote down exactly like i would do it.

But i didn't want to introduce the modulus... i thought it was to "complex";)
Last edited on
Topic archived. No new replies allowed.