Question

In: Computer Science

Using C++ Giving change. Implement a program that directs a cashier how to give change. The...

Using C++

Giving change. Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer. Compute the difference, and compute the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return.

Solutions

Expert Solution

Please find the required python script:

#=======================================================================

#include <iostream>

using namespace std;

int main() {

float amount_due, amount_rec;

int total_cents,remaining_cents,dollars=0, quarters=0, dimes=0, nickels=0, pennies=0;

cout<<"Amount due: ";

cin>>amount_due;

cout<<"Amount received: ";

cin>>amount_rec;

while(amount_due>amount_rec)

{

cout<<"Insufficient amount received! Re-enter: ";

cin>>amount_rec;

}

if(amount_due==amount_rec)

{

cout<<"Perfect amount received, No change due!!";

}

else{

total_cents = (amount_rec*1000-amount_due*1000)/10; // This will convert the due amaount to cents

dollars = (total_cents/100);

remaining_cents = total_cents - dollars*100;

quarters = (remaining_cents/25);

remaining_cents = remaining_cents - quarters*25;

dimes = (remaining_cents/10);

remaining_cents = remaining_cents - dimes*10;

nickels = (remaining_cents/5);

remaining_cents = remaining_cents - nickels*5;

pennies = (remaining_cents/1);

cout<<"\nChange to give:\n";

cout<<"Dollars: "<<dollars<<", Quarters: "<<quarters<<", Dimes: "<<dimes<<", Nickels: "<<nickels<<", Pennies: "<<pennies<<"\n";

}

}

#========================================================================

Note: Please mind the indentation in the script! A reference image of the script is being given at the last.

Sample run:

Script image:

Hope tis helps!

**************** PLEASE THUMBS UP!!!!!!!!!!! ****************


Related Solutions

in C++ For this program, you are going to implement a stack using an array and...
in C++ For this program, you are going to implement a stack using an array and dynamic memory allocation. A stack is a special type of data structure that takes in values (in our case integers) one at a time and processes them in a special order. Specifically, a stack is what's called a first-in-last-out (FILO) data structure. That is to say, the first integer inserted into the stack is the last value to be processed. The last value in...
only using C (not C++) Implement a program that counts the words and prints their frequencies....
only using C (not C++) Implement a program that counts the words and prints their frequencies. In particular, the program extracts “words” from one or more text files, from a pipe, or from the console, and prints to the console the list of words found and their associated frequencies. Note that your project submission is restricted to only using the following system calls: open(), close(), read(), write(), and lseek() for performing I/O. You are allowed to use other C library...
Implement a program as an object using a class (abstract data type) in C++ that does...
Implement a program as an object using a class (abstract data type) in C++ that does the following: 1) reads the firstName, lastName and 3 test scores of at least five students. 2) calculate student test score totals, average, letter grade for each student. 3) Display the results in a table format showing firstName, lastName, test1, test2, test3, total, average, letterGrade, of all the students. 3 files .h, .cpp, main.cpp create an object that can hold records. must get records...
USING C# Design and implement a program (name it Coins) that determines the values of coins...
USING C# Design and implement a program (name it Coins) that determines the values of coins in a jar. The program prints out the total dollars and cents in the jar. The program prompts the user to enter the number of coins (quarters, dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents as shown below. Sample run...
Using C# Design and implement a program (name it CheckPoint) that prompts the user to enter...
Using C# Design and implement a program (name it CheckPoint) that prompts the user to enter the x-coordinate then y-coordinate of a point (in a Cartesian plane) as integer values. The program prints out the entered values followed by the location of the point on the plane. The possibilities for a point are: the origin point, on the x-axis, on the y-axis, in the first quadrant, in the second quadrant, in the third quadrant, or in the fourth quadrant. Format...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
C coding • Implement, using structures and functions as appropriate, a program which requires you to...
C coding • Implement, using structures and functions as appropriate, a program which requires you to enter a number of points in 3 dimensions. The points will have a name (one alphanumeric character) and three coordinates x, y, and z. Find and implement a suitable way to stop the input loop. The program, through an appropriate distance function, should identify the two points which are the furthest apart. Another function should calculate the centre of gravity of the point cloud...
Using C# Design and implement a program (name it ProcessGrades) that reads from the user four...
Using C# Design and implement a program (name it ProcessGrades) that reads from the user four integer values between 0 and 100, representing grades. The program then, on separate lines, prints out the entered grades followed by the highest grade, lowest grade, and averages of all four grades. Format the outputs following the sample runs below. Sample run 1: You entered:   95, 80, 100, 70 Highest grade:100 Lowest grade:  70 Average grade:86.25
Write and test a C program to implement Bubble Sort. . In your C program, you...
Write and test a C program to implement Bubble Sort. . In your C program, you should do: Implement the array use an integer pointer, get the size of the array from standard input and use the malloc function to allocate the required memory for it. Read the array elements from standard input. Print out the sorted array, and don’t forget to free the memory. Debug your program using Eclipse C/C++ CDT.
USING C# Design and implement a program (name it SumValue) that reads three integers (say X,...
USING C# Design and implement a program (name it SumValue) that reads three integers (say X, Y, and Z) and prints out their values on separate lines with proper labels, followed by their average with proper label. Comment your code properly.Format the outputs following the sample runs below. Sample run 1: X = 7 Y = 8 Z = 10 Average = 8.333333333333334
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT