A third-grade teacher at Plano Elementary School wants a program that allows a s
ID: 3792621 • Letter: A
Question
A third-grade teacher at Plano Elementary School wants a program that allows a student to enter the amount of money a customer owes and the amount of money the customer paid. The program should calculate and display the amount of change, as well as how many dollars, quarters, times, nickels, and pennies to return to the customer. Display an appropriate message when the amount paid is less than the amount owed.
a. Create an IPO chart for the problem, and then desk-check the algorithm three times. For the first Desk-check, use 75.34 and 80 as the amount owed and paid, respectively. For the second desk-check, use 39.67 and 50. For the third desk-check, use 10.55 and 9.75
b. List the input, processing, and output items, as well as the algorithm, in a chart similar to the one shown earlier in Figure 5-32. Then code the algorithm into a program.
c. Desk-check the program using the same data used to desk-check the algorithm.
(continued) Algorithm 1. enter the total calories and grams cout Total calories cin totalCals; ff at cout "Grams of fat. cin fat Grams 2. if (both the total calories and grams if CtotalCals >3 0 && fatGrams 0) of fat are greater than or equal too) t eale ulate fat calories by multiplying fatCals fat Grams 9 grams of fat by 9 fat percent ealeulate fat pereentage by dividing fat calories by total ealories and then static castExplanation / Answer
#include <iostream>
using namespace std;
struct Denom {
const int cents;
const char *name;
};
//array of strucure to hold each cents detail and name
const Denom DenomArray[] = {
{ 10000, "Hundred-Dollar Bills" },
{ 5000, "Fifty-Dollar Bills" },
{ 2000, "Twenty-Dollar Bills" },
{ 1000, "Ten-Dollar Bills" },
{ 500, "Five-Dollar Bills" },
{ 100, "One-Dollar Bills" },
{ 25, "Quarters" },
{ 10, "Dimes" },
{ 5, "Nickels" },
{ 1, "Pennies" }
};
int main() {
double changeAmount,Amtsales,TenAmt;
cout<<"Amount of sale: $";
cin>>Amtsales; //accept sale amount
cout<<"Amount tendered: $";
cin>>TenAmt; //accept tendered amount
changeAmount=TenAmt-Amtsales;//find change amount
cout<<"The change is . . . "<<changeAmount<<endl;
//Convert change
int cents = 100 * changeAmount;
for (int i = 0; i < sizeof(DenomArray) / sizeof(DenomArray[0]); ++i) {
if((cents / DenomArray[i].cents)!=0)
{
cout<<(cents / DenomArray[i].cents) <<" "<<DenomArray[i].name <<' ';
}
cents %= DenomArray[i].cents;
}
}
======================================================================
akshay@akshay-Inspiron-3537:~/Chegg$ g++ doll.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Amount of sale: $120
Amount tendered: $150
The change is . . . 30
1 Twenty-Dollar Bills
1 Ten-Dollar Bills
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.