answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Liono4ka [1.6K]
2 years ago
9

Write the pseudocode that determines the change to be dispensed from a vending machine. An item in the machine can cost between

25 cents and a dollar, in 5-cent increments (25, 30, 35, .. . 90, 95, or 100), and the machine accepts only a single dollar bill to pay for the item. Requirements and example output. (bold items are user input,) . Only coins with a non-zero value should be displayed Item price must be 25 cents to a dollar, in 5-cent increments. Enter item price: 75 You bought an item for 75 cents and gave me a dollar. Your change is: 1 quarter If more than one coin is returned, the word should be plural with an "s" at the end Ifonly one coin is returned, the word should not have an "s" at the end. Item price must be 25 cents to a dollar, in 5-cent increments Enter item price: 35 You bought an item for 35 cents and gave me a dollar. Your change is: 2 quarters 1 dime 1 nickel
Computers and Technology
1 answer:
tatuchka [14]2 years ago
6 0

Answer:

input price

set change to hundred minus price

set quarter to change divided by 25

set change to change mod 25

set dime to change divided by 10

set change to change mod 10

set nickel to change divided by 5

set change to change mod 5

set penny to change

print "You bought an item for price cents and gave me a dollar. Your change is: "

if quarter is equal to 1

print quarter

else if quarter is greater than 1

print quarter with "quarters"

if dime is equal to 1

print dime

else if dime is greater than 1

print dime with "dimes"

if nickel is equal to 1

print nickel

else if nickel is greater than 1

print nickel with "nickels"

if penny is equal to 1

print penny

else if penny is greater than 1

print penny with "pennies"

Explanation:

One more understandable way of writing the above code is to use different names for change as:

input price

set change to hundred minus price

set quarter to change divided by 25

set quarter_remainder to change mod 25

set dime to quarter_remainder divided by 10

set dimes_remainder to quarter_remainder mod 10

set nickel to dimes_remainder divided by 5

set nickel_remainder to dimes_remainder mod 5

set penny to nickel_remainder

print "You bought an item for" price"cents and gave me a dollar. Your change is: "

if quarter is equal to 1

print quarter "quarter"

else if quarter is greater than 1

print quarter "quarters"

if dime is equal to 1

print dime "dime"

else if dime is greater than 1

print dime "dimes"

if nickel is equal to 1

print nickel "nickel"

else if nickel is greater than 1

print nickel "nickels"

if penny is equal to 1

print penny "penny"

else if penny is greater than 1

print penny "pennies"

I will explain the pseudocode with help of an example:

Suppose price = 75

Then change = 100 - price = 100 - 75 = 25

change = 25

quarter = change/25 = 25/25 = 1

quarter = 1

quarter_remainder = change % 25 = 25%25 = 0

dime = 0/10 = 0

Now all other values are 0.

Now the following line is printed on screen:

You bought an item for 75 cents and gave me a dollar. Your change is:

Now program moves to if part

if quarter == 1

This is true because value of quarter is 1

print quarter "quarter"

Now the following line is printed on screen:

1 quarter

So the complete output of the pseudocode is:

You bought an item for 75 cents and gave me a dollar. Your change is:

1 quarter

You might be interested in
A mistake programmers often make with loops is that they ____.
Soloha48 [4]

I think the best answer is D. Initialize the loop control variable prior to entering the loop body.

Please correct me if I'm wrong!! I'd be happy to fix it!! :)

4 0
2 years ago
#Imagine you're writing a program to check if a person is
irakobra [83]

Answer:

i hope the program below will help you!

Explanation:

5 0
2 years ago
A colleague sent you an awesome article about using proper ergonomics while sitting at the computer. You don't have time to read
lys-0071 [83]

Answer: Select the article attachment and save it to your computer.

Explanation:

5 0
2 years ago
Enter an input statement using the input function at the shell prompt. When the prompt asks you for input, enter a number. Then,
Pavel [41]

Answer:

<u>Explanation:</u>

An input statement using the input function at the shell prompt is as follows:

If a prompt asks for a input, a number is to be added

num = input ('Number: ')

num = num + 1

print(num)

Explanation of results: This gives error at line num= num + 1 as cannot convert int object to str implicitly

8 0
2 years ago
Write a method called justFirstAndLast that takes a single String name and returns a new String that is only the first and last
NemiM [27]

Answer:

Answer is in the attached screenshot.

Explanation:

Using regex to split a given input string via whitespace, then returns the first and last element of the array.

6 0
2 years ago
Other questions:
  • Suppose that you have declared a numeric array named numbers, and two of its elements are numbers[1] and numbers[5]. you know th
    5·1 answer
  • Ismael would like to insert a question mark symbol in his document. What steps will he need to follow to do that?
    5·2 answers
  • Adrian has decided to create a website to catalog all the books he has in his personal library. He wants to store this informati
    11·2 answers
  • Mark T for True and F for False. No single person or government agency controls or owns the Internet. The W3C is responsible for
    5·1 answer
  • Justin signed a rental agreement for his new condo. How long is his lease? a p e x
    15·1 answer
  • The elements of an integer-valued array can be initialized so that a[i] == i in a recursive fashion as follows: An array of size
    10·1 answer
  • A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a fi
    12·1 answer
  • Explain the emerging trends in microcomputer technology in relation to size​
    11·1 answer
  • Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binar
    12·1 answer
  • Illustrate why Sally's slide meets or does not meet professional expectations?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!