Question

Write the algorithm that determines the change to be dispensed from a vending machine. An item...

Write the algorithm that determines the change to be dispensed from a vending machine. An item in the machine can cost between 5 cents and 1 dollar, in 5-cent increments (5,10,15,......90, 95, or 100), and the machine accepts only a single dollar bill to pay for the item. The user will provide the price and the program will output the price and calculate and output the total change and how many quarters, dimes and nickels need to be dispensed. DO NOT USE REPETITION OR SELECTION STATEMENTS TO SOLVE THIS--- You must use Div & Mod! (Division and Modulo)---- ( C++ )

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Executable code:

import java.util.Scanner;
public class VendingMachine{
public static void main(String args[])
{
Scanner keyboard=new Scanner(System.in);
int n1,amount,n2,n3,n4,n5;
System.out.println("Enter price of item (from 20 cents to a dollar, in 5-cents):");
n1=keyboard.nextInt();
System.out.println("You bought an item for "+n1+" cents and gave me adollar");
System.out.println("So your change id");
amount=100-n1;
n2=amount/25;
amount=amount%25;
n3=amount/10;
amount=amount%10;
n4=amount/5;
amount=amount%5;
n5=amount;
System.out.println(n2+" quarters");
System.out.println(n3+" domes");
System.out.println(n4+" nickels");
System.out.println(n5+" pennies");
}
}

Output:

Add a comment
Know the answer?
Add Answer to:
Write the algorithm that determines the change to be dispensed from a vending machine. An item...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ HW Question Your program will simulate a simple change maker for a vending machine. It...

    C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...

  • Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to...

    Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to enter a bill value (1 = $1 bill, 5 = $5 bill, etc.) and the price of an item they want to buy in pennies and calculate their change amount in dollars, quarters, dimes, nickels, and pennies. Your code should start like this: ## # This program simulates a vending machine that gives change # Define constants PENNIES PER DOLLAR = 100 PENNIES PER...

  • All items at a "Penny Fair" are priced less than $1.00. Write a program that makes...

    All items at a "Penny Fair" are priced less than $1.00. Write a program that makes change with a minimum number of coins when a customer pays for an item with a one dollar bill. Prompt for the item price in cents, report the change due, and the number of coins of each denomination required. Use only quarters, dimes, nickels, and pennies for change (no 50 cent pieces). See sample output but your program should work for any item price....

  • The California student chapter is co-sponsoring a tea vending machine with a heavily subsidized price of...

    The California student chapter is co-sponsoring a tea vending machine with a heavily subsidized price of 15 cents a cup. Design a Mealy FSM for the vending machine assuming the students can load nickels (input N) and dimes (input D), only one coin at a time. If the user tries to enter two coins at the same time, the vending machine would not allow it, i.e. it will stay in the same state. If the user pays more than 15...

  • Pyhton Program : Write a coffee vending machine class. Include fields giving the number of cups...

    Pyhton Program : Write a coffee vending machine class. Include fields giving the number of cups of coffee available, the cost of one cup of coffee, and the total amount of money inserted by the user. This machine requires exact change. Include one constructor which stocks the machine with a quantity and price of coffee specified as parameters. Include the following methods; menu() // display the quantity and price of coffee insert(int quarters, int dimes, int nickels) // insert the...

  • Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10...

    Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters, and 10 pennies. 2. Repeatedly prompt the user for a price in the form xX.xx, where X denotes a digit, or to enter q' to quit 3. When a price is entered a. If the price entered is negative, print an error message and start over requesting either a new price or to quit (indicated by entering a 'q)...

  • 1. Create a new multi-class Java program which implements a vending machine simulator which contains the...

    1. Create a new multi-class Java program which implements a vending machine simulator which contains the following functionality: A) At program startup, the vending machine is loaded with a variety of products in a variety of packaging for example soda/tonic/Coke in bottles, peanuts in bags, juice in cartons, etc. Also included is the cost of each item. The program should be designed to easily load a different set of products easily (for example, from a file). Also at program startup,...

  • A vending machine sells a variety of snacks for $0.65; it only accepts dollars. It provides...

    A vending machine sells a variety of snacks for $0.65; it only accepts dollars. It provides $0.35 in change in nickels, dimes and quarters, using the smallest number of coins possible. The change controller takes inputs from a quarter counter (1-bit), dime counter (2-bits), and nickel counter (3-bits). It outputs the number of quarters (1-bit), dimes (2-bits) and nickels (3-bits) to be dispensed, or asserts "no change" (1- bit) if the machine is unable to make exact change. Design a...

  • Overview - Vending Machine For this project, we will simulate a vending machine where, for simplicity,...

    Overview - Vending Machine For this project, we will simulate a vending machine where, for simplicity, all of the items in the machine are the same price of $1.25 The vending machine can receive Nickels, Dimes, Quarters, and one dollar Bills. The user can add money, ask for the product, ask for their money back, or walk away (exit). The program will interact with the user and allow the following commands: N - adds nickel D - adds dime Q...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT