Write a set of detailed, step-by-step instructions in English to calculate the fewest number of dollar bills needed to pay a bill of amount TOTAL. For example, if TOTAL is $97, the bills would consist of one $50 bill, two $20 bills, one $5 bill, 2$and $1 bills. (For this exercise, assume that only $100, $50, $20, $10, $5,2$and $1 bills are available.)
b. Repeat Exercise 6a, but assume the bill is to be paid only in $1 bills.
To simplify matters, you will all work with a sum of $283.00
i would like to have a structured chart design
and pseudocode alogrithm along with the actual coding on c++
1
Expert's answer
2012-02-24T08:40:25-0500
For using fewest number of dollar bills, all bills must be biggest amount. For example, at first must be calculate maximum number of $100 dollar bill, then $50 dollar bill, till $1 dollar bill.
Algorithm: 1. Calculate maximum number of $100 bills as integer part of division total amount by bill’s amount ($100 for this case). 2. Decrease total amount by amount of $100 bills which calculated in previous step. 3. Repeat first and second steps for other bills in descending order.
Code of program:
#include <iostream> #include <conio.h>
using namespace std;
int main(int argc, char* argv[]) { /// Number of bills. const int billsNumber = 7;
/// Input value which would split for fewest number of dollar bills. int totalAmount;
/// Total number of bills. int totalBillsNumber = 0;
do { & /// Read total amount. & cout<<"Input the total amount: "; & cin>>totalAmount;
& int count = 0;
& /// For each bill calculate it's max number. & while (totalAmount > 0) & { & /// Calculate number of bills amount of bills[count] as a integer part of & /// division amount to bill's amount. & int billsNumber = totalAmount / bills[count];
& totalBillsNumber += billsNumber;
& /// Display result. & cout<<"Number of $"<<bills[count]<<"\tbills is "<<billsNumber<<endl;
& /// Number of bills is zero for any bills with less amount. & while(count < billsNumber) & { & /// Display result. & cout<<"Number of $"<<bills[count]<<"\tbills is 0"<<endl; & count++; & }
& cout<<"Total number of bills is "<<totalBillsNumber<<endl;
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment