Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make Change program - C++ Write a program to input two float values. The first f

ID: 668296 • Letter: M

Question

Make Change program - C++

Write a program to input two float values. The first float is the cost of some purchase made, or the cost of goods, and the second is the payment value towards the cost. You are to determine the change (if any) to return to the customer. You must also determine if they gave you enough money to cover the cost, if they didn't, print out you are short on funds, so pay more.
The change should be the number of 20 dollar bills to return, then the number of 10's, 5's, and 1's in bills. Then the change for coins, the number of 50 cents, .25 cents (quarters), 10 cents (dimes), 5 cents (nickels), and pennies. DO NOT print out 0 for any of the above values (if they don't get any 20 dollar bills back, don't print "0 20 dollar bills". You just don't print anything.)
Print out the 'cost' and the 'payment' and then the amount of change to return.

Example:

0.81     1.00
Example output:
purchase   pay   change
0.81          1.00    1 dime, 1 nickel, 4 pennies

NOTE: Can't use arrays or classes yet as we haven't covered them.

Explanation / Answer

include <stdio.h>
void Dispenser(int, int *, int *, int *, int *);       /* Determines how many of each kind of coin to dispense */
int main(void)
{
/* Declare variables */
double amount_paid,       /* The amount of money paid by the user */
amount_due;              /* The amount of money that is due */
int amount_left,        /* The amount of money left after deductions */
dollar_qty,            /* The quantity of dollars in change */
quarter_qty,           /* The quantity of quarters in change */
dime_qty,             /* The quantity of dimes in change */
nickel_qty,          /* The quantity of nickels in change */
penny_qty;          /* The quantity of pennies in change */
/* Prompt user for the amount paid and the amount due */
printf(" Enter the money amount paid: $");
scanf("%lf", &amount_paid);  
printf(" Enter the money amount due: $");
scanf("%lf", &amount_due);
/* Convert from real to whole numbers to ensure accuracy */
amount_paid = amount_paid * 100 + 0.5;
amount_due = amount_due * 100;
/* Subtract amount paid from amount due and get the amount left and determine dollar quantity */
amount_left = amount_paid - amount_due;
dollar_qty = amount_left / 100;
/* Call function */
Dispenser(amount_left, &quarter_qty, &dime_qty, &nickel_qty, &penny_qty);
/* Display change amount */
printf(" CHANGE AMOUNT DISPENSED");
printf(" ----------------------- ");
printf(" $1: %d", dollar_qty);
printf(" $0.25: %d", quarter_qty);
printf(" $0.10: %d", dime_qty);
printf(" $0.05: %d", nickel_qty);
printf(" $0.01: %d ", penny_qty);
return 0;  
}
void Dispenser(int amt_left, int *quarters, int *dimes, int *nickels, int *pennies)
{
int total_change,                  /* Total change amount */
    total_quarters,               /* The total quantity in quarters */
    total_dimes,                 /* The total quantity in dimes */
    total_nickels,              /* The total quantity in nickels */
    total_pennies;             /* The total quantity in pennies */
/* Determine change amount and quantity */
total_change = amt_left % 100;
total_quarters = total_change / 25;
total_change = total_change % 25;
total_dimes = total_change / 10;
total_change = total_change % 10;
total_nickels = total_change / 5;
total_change = total_change % 5;
total_pennies = total_change;
/* Assign totals to output pointer variables */
*quarters = total_quarters;
*dimes = total_dimes;
*nickels = total_nickels;
*pennies = total_pennies;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote