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...
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 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
Implement a C++ program to implement the Banker’s algorithm for deadlock avoidance. Number of process 5,...
Implement a C++ program to implement the Banker’s algorithm for deadlock avoidance. Number of process 5, number of resources 3 and the number of instances of each given resource is in available. You should complete the functionalities for safe state check and resource request processing. To Do 1. Complete the definition of isSafe function. The function take, the process array, 1D array of available resources, 2D array storing current allocation, and 2D array of current need. The function does not...
(Write a C# program DO NOT USE CLASS)Implement the merge sort algorithm using a linked list...
(Write a C# program DO NOT USE CLASS)Implement the merge sort algorithm using a linked list instead of arrays. You can use any kind of a linked structure, such as single, double, circular lists, stacks and/or queues. You can populate your list from an explicitly defined array in your program. HINT: You will not be using low, middle and high anymore. For finding the middle point, traverse through the linked list while keeping count of the number of nodes. Break...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases in which the initial unit is Fahrenheit or something not recognizable. Your program should incorporate Fahrenheit to Celsius, Fahrenheit to Kelvin and unknown initial units (display an error message for this last one). You must use functions to calculate Fahrenheit degrees.
write C program to implement the priority queue with the operation insert
write C program to implement the priority queue with the operation insert
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT