Part C Code a do while loop to make change for a customer In

Part C. Code a do while loop to make change for a customer. Input the amount of money put into a vending machine Change that value to cents. Input the amount of the purchase. Change that value to cents. Subtract the two values. Determine the customer\'s change in number of quarters, dimes, nickels, and pennies, using integer arithmetic. Hint: cents 25 number of quarters cents %25-remaining cents to change into dimes nickels, etc. Keep making change for different purchases until the user tells you to stop. Make change for 3 or 4 purchases. Turn in the source and 3 or 4 outputs from Part C.

Solution

#include <iostream>

using namespace std;

void makePurchase()
{
float money;
cout << \"Enter amount of money put into vending machine : \";
cin >> money;

float purchase_money;
cout << \"Enter amount of purchase : \";
cin >> purchase_money;

int amount = (int)(money*100);
int purchase = (int)(purchase_money*100);

int change = amount - purchase;
if (change < 0)
{
cout << \"Purchase should be less than amount.\" << endl;
return;
}

if (change > 0)
{
cout << \"Change is: \";
}

int quarters = change/25;
change = change % 25;

int dimes = change / 10;
change = change % 10;

int nickel = change / 5;
change = change % 5;

int pennies = change;


if (quarters > 0)
{
cout << quarters << \" quarters \";
}

if (dimes > 0)
{
cout << dimes << \" dimes \";
}

if (nickel > 0)
{
cout << nickel << \" nickels \";
}

if (pennies > 0)
{
cout << pennies << \" pennies \";
}
}

int main()
{
char choice;
do
{
makePurchase();
cout << \"make more change (y/n): \";
cin >> choice;
} while(choice == \'y\');

}

 Part C. Code a do while loop to make change for a customer. Input the amount of money put into a vending machine Change that value to cents. Input the amount o
 Part C. Code a do while loop to make change for a customer. Input the amount of money put into a vending machine Change that value to cents. Input the amount o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site