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

Write the code for the computeChange function that will determine how many quart

ID: 3548729 • Letter: W

Question

Write the code for the computeChange function that will determine how many quarters, dimes and nickel will be returned to the customer for his purchase of a VendItem. Assume 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 nickles in the change. The function is passed the price of the item and the cash tendered for the item

int changecoins[3];


void computeChange (double price, double cash)

{

Explanation / Answer

#include<iostream>
using namespace std;
int changecoins[3];
void computeChange (double price, double cash)
{
if(price>cash)
{
cout <<"You Dont have Enough cash to buy item :" << endl;
}
else
{
int change = static_cast<int> ((cash-price)*100);
if(change>0)
{
changecoins[0] = change/25;
change = change - changecoins[0]*25;
changecoins[1] = change/10;
change = change - changecoins[1]*10;
changecoins[2] = change/5;
}
}
}
int main()
{
computeChange(3.5,6);
cout << "No of quarters to be returned is " << changecoins[0] << endl;
cout << "No of dimes to be returned is " << changecoins[1] << endl;
cout << "No of nickels to be returned is " << changecoins[2] << endl;
return 0;
}