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

In C++ Code a do while loop to make change for a customer. Input the amount of m

ID: 3794222 • Letter: I

Question

In 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.

Explanation / Answer

#include <iostream>
using namespace std;

int main() {
   int amount;
   int purchase;
   int change;
   int check;
   int quarters;
   int dimes;
   int nickels;
   int pennies;
   int remaining;
   cout << "Input the amount to be added in the vendor machine ";
   cin >> amount;
   amount = amount * 100 ;
   do{
   cout << "enter the amount of the purchase ";
   cin >> purchase;
   purchase = purchase * 100;
   amount = amount - purchase;
   cout << "any other purchase ? 1 for yes : 0 for no";
   cin >> check;
   }while(check !=0);

   quarters=amount /25;
   remaining=amount % 25;
  
   dimes=remaining/10;
   remaining=remaining%10;
   nickels=remaining/5;
   remaining=remaining % 5;
  
cout << " THe change is " << amount/100 << "dollars "<<endl << "Change you get :"<<endl <<"quarters = "<< quarters <<endl<<"dimes =" <<dimes<<endl<<"nickels ="<<nickels <<endl;
  
   return 0;
}