Here\'s the question. I will post an example of my last assignment in a comment.
ID: 3547134 • Letter: H
Question
Here's the question. I will post an example of my last assignment in a comment. The question is as follows:
Create the logic for a program that continuously prompts the user for a number of dollars until the users enters 0. Pass each entered amount to a conversion method that displays a breakdown of the passed amount into the fewest bills; in other words, the method calculates the number of 20s, 10s, 5s, and 1s needed. Their is to be no declarations at the top. Again these must use methods.
Here are extra tip from the instructor: I just realized that the book did not cover a topic that will make the Chapter 9 Assignment 3 solution much easier. The topic I am referring to is the modulus operator.
When doing math in programming, everyone should be familiar with the + - * and / operators. The modulus operator returns the remainder of a division problem. The modulus operator is the percent character (%).
For example, 34 % 3 will return 1 since the result of that division problem will be 11 remainder 1. Another example is 73 % 20 which would return 13 since 73 divided by 20 would be 3 remainder 13.
If you use this operator it will greatly reduce the complexity of your program.
Solution to last weeks so you all can see the formatting:
Start
main() // Call the conductor
Stop
main()// Manage the orchestra
greetuser() // Greet the user
inputNums() // Call the user input method
finishUp() // End or restart the program
return
greetUser()// Hello user, would you like to play a game?
Declarations
String beginProg
endDeclarations
Output
Explanation / Answer
Start
main() // Call the conductor
Stop
main()// Manage the orchestra
Declarations
num amount
endDeclarations
input "Enter Amount to find changes 20s, 10s, 5s, and 1s :", amount
do
print_changes(amount)// Call the print_changes method
input "Enter Amount to find changes 20s, 10s, 5s, and 1s :", amount
while amount not equal to zero.
return
print_changes(num amount)
Declarations
num no_of_twentys
num no_of_tens
num no_of_fives
num no_of_ones // Declare variables.
endDeclarations
no_of_twentys = amount/20
amount = amount - no_of_twentys*20
no_of_tens = amount/10
amount = amount - no_of_tens*10
no_of_fives = amount/5
no_of_ones = amount - no_of_fives*5
if no_of_twentys is not equal to zero
Output " No of 20's is " , no_of_twentys
if no_of_tens is not equal to zero
Output " No of 10's is " , no_of_tens
if no_of_fives is not equal to zero
Output " No of 5's is " , no_of_fives
if no_of_ones is not equal to zero
Output " No of 1's is " , no_of_ones
return