Write the algorithm and a program in C++ code for a cashier to give the customer
ID: 3800553 • Letter: W
Question
Write the algorithm and a program in C++ code for a cashier to give the customer back the exact number of dollars, quarters, dime, nickel and pennies for an order involving single or a combination of choices of meal and payment in cash by the customer. Write the algorithm and a program in C++ code for a cashier to give the customer back the exact number of dollars, quarters, dime, nickel and pennies for an order involving single or a combination of choices of meal and payment in cash by the customer. Write the algorithm and a program in C++ code for a cashier to give the customer back the exact number of dollars, quarters, dime, nickel and pennies for an order involving single or a combination of choices of meal and payment in cash by the customer.Explanation / Answer
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main ()
{
double moneyOwed = 0.0;
double moneyPaid = 0.0;
double change = 0.0;
int change1 = 0;
int dollars = 0;
int quarters = 0;
int dimes = 0;
int nickels = 0;
int pennies = 0;
cout<<"Enter money owed: $";
cin>>moneyOwed;
cout<<"Enter money paid: $";
cin>>moneyPaid;
cout<<endl;
if (moneyOwed > moneyPaid)
{
cout<<"The amount that was given is not enough, please pay the full amount.";
cout<<endl;
cout<<endl;
}
else
{
cout<<fixed<<setprecision(2);
change = moneyPaid - moneyOwed;
change1 = change*100;
dollars = change1/100;
quarters = change1%100/25;
dimes = change1%100%25/10;
nickels = change1%100%25%10/5;
pennies = change1%100%25%10%5;
cout<<"Change due: $"<<change<<endl;
cout<<"Dollars: "<<dollars<<endl;
cout<<"Quarters: "<<quarters<<endl;
cout<<"Dimes: "<<dimes<<endl;
cout<<"Nickles: "<<nickels<<endl;
cout<<"Pennies: "<<pennies<<endl;
cout<<endl;
cout<<endl;
}
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.