4. (16 points) Write the code for a function called com computeChange that will
ID: 3908858 • Letter: 4
Question
4. (16 points) Write the code for a function called com computeChange that will determi and nickels will be returned to the customer for the purchase of a Vendltem in Question 3. Assume the globally s always hold the 3 values for the change coin categories. Position will be the number of quarters in the change, position 1 in the change, and position 2 will be the number of nickels in the change. The function is passed the price of the item and the cash tendered for the item. (HINT: An algorithm could be to subtract 25 cents from the change repeatedly until less than 25 cents remains, then subtract 10 cents repeatedly, then 5 cents, counting each successful subtraction in the appropriate position of the array.) will be the number of dimes const int COIN TYPES = 3; int changeCoins[COIN TYPES]: l/globally declared and accessible void computeChange(double price, double cash)Explanation / Answer
const int COIN_TYPES = 3;
int changeCoins[COIN_TYPES];
void computeChange(double price, double cash) {
double change = (cash - price) * 100; // converting dollars to cents
changeCoins[0] = change / 25;
change = change % 25;
changeCoins[1] = change / 10;
change = change % 10;
changeCoins[2] = change / 5;
change = change % 5;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.