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

C++ Programming Write the code for a function called computeChange that will det

ID: 3906492 • Letter: C

Question

C++ Programming

Write the code for a function called computeChange that will determine how many quarters, dimes, and nickels will be returned to the customer for the purchase of a VendItem. Assume the globally declared array changeCoins always hold the 3 values for the change coin categories. Position 0 will be the number of quarters in the change, position 1 will be the number of dimes 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.

Explanation / Answer

#include <iostream>

using namespace std;
const int COIN_TYPES = 3;
int changeCoins[COIN_TYPES]; //globally declared and accessible

void computeChange(double price, double cash)
{
double returnCash = cash - price;
changeCoins[0]=returnCash/25;
returnCash=(int)returnCash%25;
changeCoins[1]=returnCash/10;
returnCash=(int)returnCash%10;
changeCoins[2]=returnCash;
}
int main()
{
double price = 66;
computeChange(price, 100);
cout<<"Quaters: "<<changeCoins[0]<<endl;
cout<<"Dimes: "<<changeCoins[1]<<endl;
cout<<"Nickels: "<<changeCoins[2]<<endl;
return 0;
}

Output:

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