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

C++ program using IF ELSE statment The customer is given the option of automated

ID: 3886919 • Letter: C

Question

C++ program using IF ELSE statment

The customer is given the option of automated checkout at retail centers. Write a program that will accept the customer's payment (in dollars and cents only) and returns the correct change back to the customer. For example, if the items purchased were $5.15 and the customer pays $10.00 the change returned would b four one dollar bills, three quarters, and one dime. If the items purchased were $5.15 and the customer pays $20.00 the change returned would be a ten dollar bill, four one dollar bills, and three quarters, and one dime. If the items purchased were $5.15 and the customer pays six dollars, then the change would be three quarters and one dime. You may assume the following constraints: The purchase price of all items will never exceed $50.00. The customer will purchase the items using a max denomination of a hundred dollar bill. The customer will only pay in whole dollars only, never in cents. The customer's payment will always be greater than the cost of the items purchased. Your program should ask for the purchase amount and also the payment amount from the user.

Explanation / Answer

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

int main ()

{

//bill is the amount to be paid and pay is the amount taken from customer

double bill = 0.00;

double pay = 0.00;

cout<<"Enter bill amount $: ";

cin>>bill;

//converting bill andd pay into integers

int p,b;

b=bill*100;

cout<<endl;

cout<<"Enter payment amount $: ";

cin>>pay;

cout<<endl;

p=pay*100;

//calculate the amount to be returned

int change=p-b;

//whole money divided by 5000 gives us required 50 dollar notes and%5000 gives us the remaining money after removing those 50 dollar notes

int _50dollars=change/5000;

int _20dollars=(change%5000)/2000;

int _10dollars=((change%5000)%2000)/1000;

int fdollars=(((change%5000)%2000)%1000)/500;

int dollars=((((change%5000)%2000)%1000)%500)/100;

//using money vARIABLE TO AVOID WRITTING LENGTHY EXPRESSION ABOVE OBTAINED

int money=((((change%5000)%2000)%1000)%500)%100;

int quarters = money/25;

int dimes =money%25/10;

int nickels =money%25%10/5;

int pennies = money%25%10%5;

cout<<"Change due: $"<<pay-bill<<endl;

//print only those whose currency notes are to be returned

if(_50dollars>0)

cout<<"Fifty: "<<_50dollars<<endl;

if(_20dollars>0)

cout<<"Twenty: "<<_20dollars<<endl;

if(_10dollars>0)

cout<<"Tens: "<<_10dollars<<endl;

if(fdollars>0)

cout<<"Fives: "<<fdollars<<endl;

if(dollars>0)

cout<<"Dollars: "<<dollars<<endl;

if(quarters>0)

cout<<"Quarters: "<<quarters<<endl;

if(dimes>0)

cout<<"Dimes: "<<dimes<<endl;

if(nickels>0)

cout<<"Nickles: "<<nickels<<endl;

if(pennies>0)

cout<<"Pennies: "<<pennies<<endl;

cout<<endl;

cout<<endl;

return 0;

}

//if my guidance proved helpful do comment and like.

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