Quick Help
import java.util.Scanner;
public class question7 {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.println("Enter price of item");
System.out.print("(from 25 cents to a dollar, in 5-cent increments): ");
int cost = console.nextInt();
int change = 100 - cost;
}
}
This runs for me and asks me to enter price, but when i enter it nothing happens because I have yet to program it in. I was wondering if someone can help me write the code so when i enter a price it outputs the change like so
Enter Price:35 Cents
Your Change is 2 quarters, One Dime, One nickel.
Not just saying the Change is 65 cents. Any help?
[740 byte] By [
cbreen12a] at [2007-11-26 17:39:36]

> I was wondering if someone can help me
> write the code so when i enter a price it outputs the
> change like so
>
> Enter Price:35 Cents
> Your Change is 2 quarters, One Dime, One nickel.
>
> Not just saying the Change is 65 cents. Any help?
Help with your homework; yes! Doing your homework; probably not.
Im not asking you to do it, I have this written already, but I am unsure of how to finish it. Its more than half done i just dont know how to do the last step.
> Your Change is 2 quarters, One Dime, One nickel.
You're going to want the print statement to look like System.out.println("your change is "+quarters+" quarters, "+dimes+" dimes, "+nickels+" nickels, and "+dimes+" dimes.");
So you're going to need int variables for each of those.
Then you need a loop to increment the "quarters" variable and decrement the "un-converted change amount" variable for as long as the "un-converted change amount" is over 25, and a similar loop for nickels and dimes.
That should be functional.
> Enter Price:35 Cents
> Your Change is 2 quarters, One Dime, One nickel.
>
> Not just saying the Change is 65 cents. Any help?
Just think of how you would do it mentally and write in down on a piece of paper. Okay, let's start:
1. The price is 35 cents and someone pays a dollar. The change is 65 cents.
2. Lets say you have counts for
number of quarters = 0
number of dimes = 0
number of nickels = 0
initially.
3. 65 is greater than 25 (quarter), so you can pay a quarter in the change, hence
number of quarters = 1
number of dimes = 0
number of nickels = 0
and the balance remaining = 65 - 25 = 40
4. Again you can take another quarter out since 40 is greater than 25 (quarter), so add a quarter to the change
number of quarters = 2
number of dimes = 0
number of nickels = 0
and the balance remaining = 40 - 25 = 15
5. Now, 15 is less than [and not equals either] 25 (quarter), hence you cannot pay any more quarters. So move onto dimes. Since 15 is greater than 10 (dime), add a dime to the change
number of quarters = 2
number of dimes = 1
number of nickels = 0
and the balance remaining = 15 - 10 = 5
6. Finally, you cannot pay out in dimes because 5 is less than 10 (dime). But 5 equals a nickel. So add a nickel and zero the balance due.
number of quarters = 2
number of dimes = 1
number of nickels = 1
and the balance remaining = 5 - 5 = 0
Problem solved!
Now all you have to do is implement this logic in Java. :p
Thank you both very much, thats all I needed! Unlike the character that had to tell me i needed you to do it for me> Help with your homework; yes! Doing your homework;> probably not.
> Thank you both very much, thats all I needed! Unlike
> the character that had to tell me i needed you to do
> it for me
>
> > Help with your homework; yes! Doing your homework;
> > probably not.
I am likely to tell you the same if you don't mention that you are looking for the logic rather than the code.
cbreen12 how did you do with that assignment?Go here http://forum.java.sun.com/thread.jspa?threadID=386151 Reply 5 for a more advanced version of the "Making Change" Algorythem (SP)