1answer.
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]
4 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]4 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
Mail merge documents use ______ to represent personal information that stored in a table.
Mice21 [21]
Mandatory
Mark brainliest please
6 0
3 years ago
Joanna accidentally leaned on her keyboard and repeatedly typed the letter z. How can she fix this mistake?
Brut [27]

Answer:

just press delete

Explanation:

5 0
3 years ago
Read 2 more answers
What is known as networking in the IT field?
Sidana [21]

Answer:

r u Kate tell me plz I love u baby tell me please

4 0
3 years ago
When using a template to compose a memorandum which key on the keyboard moves the cursor to the next field
marishachu [46]
The tab key moves the cursor to the next field in the tab order, which is set by the programmer.
8 0
3 years ago
The pointer changes shape by adding a _____ to indicate that the format painter function is active.
myrzilka [38]
The pointer changes shape by adding a paintbrush <span>to indicate that the format painter function is active. Some options would have definitely helped in answering this question. This is a great feature of Powerpoint. I hope that this is the answer that you were looking for and the answer has actually come to your desired help.</span>
4 0
3 years ago
Other questions:
  • What are the texture of metamorphic​
    12·1 answer
  • the part of the computer that contains the brain , or central processing unit , is also known the what ?
    12·1 answer
  • Does anyone know any nitro type hack??
    13·2 answers
  • Match the vocabulary word to the accurate definition. A software program that enables you to search for, interact with, and retr
    5·2 answers
  • What are the examples of debugging?​
    14·1 answer
  • On tool hackers use to get sensitive information from victims is/are:
    15·2 answers
  • What internal commands can we use when in interactive mode? can we use CLS and CD?
    6·1 answer
  • there are these numbers that I've seen before but I don't know what they mean can someone help. I will give brainiest
    8·2 answers
  • What is resource pooling?
    13·1 answer
  • A new printer has recently been installed in the office, but it does not print. What is the first source to check for informatio
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!