Determing the amount of change(money)
The output of the program should look like this:
I was able to get the inputs to work correctly by using if and else statements. The part I'm having trouble with is how to determine and print out the amount needed for each bill and coin like in the sample output above. I know the maximum amount that can be used for each bill/coin, but I'm not sure what methods to use to determine how to print out the correct amount for a certain amount of change.
This program computes the change to be given
for a purchase paid for with a $20 bill
The purchase must be less than or equal to $20
Enter amount of purchase: 0.01
Purchase amount is 0.01
Change due is 19.99
So basically, I would like to know how I would go about printing out the amount of coins/bills? I first assumed that I could use some type of loop, but I didn't know how to go on about it. Then I thought about doing if and else statements, but it was going to be a lot which would end up confusing me.
Here's what I've gotten so far, which is basically asking for user input and printing out the change only. Not the bills/coins.
I would just like some tips on how to go on about printing out the amount of bills/coins for a certain amount of change. Something to get me started.
double change = 0;
printf("This program computes the change to be given\n");
printf("for purchases paid for with a $20.\n");
printf("Purchase must be between $0.00 and $20.00\n\n");
printf("Enter purchase amount: ");
printf("\nPurchase amount: $%.2f\n", amount);
if (amount > 0.00 && amount < 20.00)
change = 20.00 - amount;
printf("Change due: $%.2f\n\n", change);
else if (amount == 20.00)
printf("No change due\n");
printf("Please enter an amount greater than $0.00 and\n");
printf("less than or equal to $20.00\n");