Question

In: Computer Science

I'm writing a program using EasyReader class. The program wil give me the how much money...

I'm writing a program using EasyReader class. The program wil give me the how much money is left. e.g. someone paid 50 pounds for their 20 pounds worth of groceries so the output will be 30 pounds. my question is, I want it to print out how the change should be made up. how many 10 pounds, 5 pounds, 2 pound and so on, is in the change. how should I write the program

Solutions

Expert Solution

Since you just need the logic to break the change into several small units, I'm going to tell you how can you do the same,

Before we begin, you should be knowing the terms division and modulus. Let me give you a little brief, in programming, a/b(read as division) gives us the quotient and a%b(read as modulus) gives us the reminder.

For example, 5/2 = 2 and 5 % 2= 1

Firstly let us assume that we want to break our change into 4 small units i.e. 10,5,2,1.

  • we have to first calculate change / 10.
  • If it is greater than 0 then we would save the value of change / 10 and calculate change % 10. From here we would get the reminder. Now change = reminder.
  • If it is 0, we repeat the same with 5,2 and 1.
  • We stop when our change becomes 0

An example would clear.

So suppose if our change is 47,

  • 47 / 10 = 4 which is greater than 0.
  • Hence we save the value 4, it means that we need 4 coins of 10 pounds in our change. Now 47 % 10 = 7. So now change = 7
  • 7 /10 = 0. so we go to calculate 7 / 5.
  • 7 / 5 = 1. so we need 4 coins of 10 pounds and 1 coin of 5 pounds in our change. Now 7 % 5 = 2. So now change = 2.
  • 2 / 10 = 0 and 2 / 5 = 0. So we go to  calculate 2 / 2
  • 2 / 2 = 1, so we need 4 coins of 10 pounds, 1 coin of 5 pounds and 1 coin of 2 pounds n our change.
  • Now, 1 % 2 = 0. So. now change = 0 and since change became 0. we stopped.

Solution ends.

Please comment and let me know if you have any further doubts. Please upvote this answer if you like it.

Thank you.

Have a good day.


Related Solutions

Give me some Literary writing of divorce?
Give me some Literary writing of divorce?
1a) If I'm writing a program which involves many insertion and deletion operations, and memory is...
1a) If I'm writing a program which involves many insertion and deletion operations, and memory is not a concern, which of the following should I choose to hold my data? A: linked list B: fixed-size array C: dynamic array D: any of the above 1b) What about if I'm writing a program and I want the program to be flexible on the data with various sizes, and the program also needs to provide fast access to the data? Which of...
Should interest groups be limited in how much money they can give to a candidate they...
Should interest groups be limited in how much money they can give to a candidate they support? Does this limitation help our society in any way. How does limiting campaign contributions by interest groups conflict with the First Amendment's Freedom of Speech or the 5thAmendment's right to property? Consult the facts of the case in the Supreme Court case "Citizens United." Explain with examples and cite evidence for your view.
Hello, Please give me step by step answer (with screenshot) of SPSS using the ANOVA program...
Hello, Please give me step by step answer (with screenshot) of SPSS using the ANOVA program to answer the following question. Chegg gave different answers. A researcher would like to find out whether a particular diet affects a person’s cholesterol reading. She records the cholesterol readings of 23 men who ate cow meat for dinner every night, 24 men who ate chicken and 19 men who ate pig; her data appears in the table to the right. She wants to...
I need a speech to give me a girlfriend. I want to tell her how much...
I need a speech to give me a girlfriend. I want to tell her how much I love her and how much she means to me. I want to tell her that she is the only thing I think of from morning till night. Her name is Angie. she is the most beautiful girl I have ever met and I need something like a paragraph to show how much I love her. I want it so sweet and loving that...
JC looks at the prescription for Flexeril and States I'm glad you didn't give me that...
JC looks at the prescription for Flexeril and States I'm glad you didn't give me that Valium. they gave me Valium last time and that stuff knocked me out how would you respond to JC
Advice Columnist: I'm writing to warn others about unsigned contracts. I wish someone had warned me...
Advice Columnist: I'm writing to warn others about unsigned contracts. I wish someone had warned me to get this contract in writing. This is what happened. In June of 2017, I paid $450 to reserve a reception hall for our 50th wedding anniversary, which is July 23, 2018. On January 20, 2018, my husband passed away. I phoned the reception hall immediately and told them what had happened and requested a refund. This was a good six months before the...
How much money can Bank A create by making loans? How much money can the banking...
How much money can Bank A create by making loans? How much money can the banking system as a whole create? Show your detailed calculation. What can you say about the relationship between the required reserve ratio and money creation? Why do some banks hold a part in excess reserves instead of loaning all excess reserves out? What are some other ways that banks may use a portion of their excess reserves?
Write a Python program that will calculate how much money you will have when you invest...
Write a Python program that will calculate how much money you will have when you invest a given amount of money over a set number of years with a given interest rate. The program takes as user input how much money to invest and the yearly interest rate and calls a calculateEarnings function using those two inputs as the parameters initialMoney and interestRate. Both of the user inputs should be able to be entered in decimal numbers. The calculateEarnings function...
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want...
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want to plot a 3D animated orbit which is a 60 by 58 nautical miles orbit. Can you provide a code or some idea of how to plot an orbit like this in 3D?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT