• Post Reply Bookmark Topic Watch Topic
  • New Topic

vending machine and showing change in coins  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure how to avoid getting negative numbers of coins, and can anybody help me use casting and mod to show how many quarters, dimes, nickels, and pennies there are?
 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leyil,
Welcome to CodeRanch!

Take it slow and start with smaller code, get that to work and proceed from there. It's harder to debug a lot of code. In the code you posted I see an infinite loop:


In the spirit of starting small, can you write code that:
1) Prints out the menu and lets the user enter coins until $2 is reached?
2) Determines how much the requested item costs?
3) Determines the amount of change (should involve subtraction and the cost)
4) Determines if a quarter is too much change (I wouldn't use mod for this either)
5) Determines if a dime is too much change
etc
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!