Question

You have a large collection of pennies and wish to change them into dollar bills at...

You have a large collection of pennies and wish to change them into dollar bills at the bank, with quarters, dimes, nickels, and pennies being used for any remainder. Prompt for the number of pennies and produce output as shown below.

  • Write the pseudo code
  • Desk check
  • Modify if necassary
  • Code
  • Compare output

Output:

How many pennies do you have (must be greater than 100)? [Assume user inputs 641]

641 pennies can be changed at the bank as follows:
Dollars: 6
Quarters: 1
Dimes: 1
Nickels: 1
Pennies: 1


Solve in C++.

Homework Answers

Answer #1

In the given problem we have to write a code which gives the output in number of dollars, quarters, dimes , nickles and pennies with the given input of no. of pennies.

In order to solve the problem let us have the conversion rate

1 Dollar = 100 pennies

1 Quarter = 25 pennies

1 dime = 10 pennies

1 nickle = 5 pennies

Let me explain the Approach I am going to use

1. In order to solve the problem we have to divide the given pennies into parts:-

Step 1: Now first we need to find the no. of dollars considering 1 Dollar = 100 pennies

No. of dollars = Total pennies/100;

Reminder of dollars = Total Pennies %100; ( In order to find the remainder we use % operator)

Step 2: Now to find the no. of quarters we will divide the Reminder of dollars by 25 as 1 Quarter = 25 pennies

No. of Quarter = Reminder of dollars / 25;

Reminder of Quarter = Reminder of dollars % 25;

Step 3: Now to find the no. of Dimes we will divide the Reminder of Quarter by 10 as 1 Dime = 10 pennies

No. of Dime= Reminder of Quarter / 10;

Reminder of Dime = Reminder of Quarter % 10;

Step 4: Now to find the no. of Nickles we will divide the Reminder of Dime by 5 as 1 Nickle = 5 pennies

No. of Nickles = Reminder of Dime /  5;

Remaining pennies = Reminder of Dime% 5;

Hence we will get the answer.

Now let us write the code:-

#include<iostream> // Header file
using namespace std;
int main()
{
   int p , d ,qu ,di , ni , pen; // declaring the variables
int d1,q1,n1,di1; // declaring the reminders(you can use any name)

cout<<" How many pennies do you have (must be greater than 100)?";
cin>>p; // Taking the input

d = p / 100; // finding the dollars
d1 = p % 100; // finding reminder for quarter

qu = d1 / 25; // finding the quarters
q1 = d1 % 25; // finding reminder for dimes

di = q1 / 10; // finding the dimes
d1 = q1 % 10; // finding reminder for nickles

ni = di1 / 5; // finding the nickels
pen = di1 % 5; // finding reminder for the remaining pennies

//output
cout<<"\n Dollars:"<<d;

cout<<"\n Quarters: "<<qu;

cout<<" \n Dimes:"<<di;

cout<<" \n Nickles"<<ni;

cout<<"\n Pennies"<<pen;

}

Here is the code , you may find the error stray 240 in program if you copy paste the code , this is common is IDEs hence I'll request you to run the unwanted spaces and then run the program.

Feel free to reach out to me in comment section.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
program has to be written in X86 processor assy language. Write a program that find the...
program has to be written in X86 processor assy language. Write a program that find the minimum number of coins that can represent an amount of money under $1. The amount of money is a random number between 0 and 99 (cents). The randomRange procedure is used to get a random number. Review the sample code in lab4.asm and run it to see how randomRange works. Each time randomRange is called, it creates a random number between 0 and the...
For this assignment you need to write a parallel program in C++ using OpenMP for vector...
For this assignment you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is: #pragma...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
Design a FSM for a Vending Machine In this task, you will design a FSM for...
Design a FSM for a Vending Machine In this task, you will design a FSM for a simple (albeit strange) vending machine of office supplies. The vending machine sells three possible items, each at a different cost: Item Cost Pencil 10 cents Eraser 20 cents Pen 30 cents The vending machines accepts nickels (worth 5 cents), dimes (worth 10 cents), and quarters (worth 25 cents). Physically, it is only possible to insert a single coin at a time. The vending...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT