• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with assignment, loop not terminating  RSS feed

 
Isabel Munoz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been working on this code for a simple slot machine in java for weeks!! I can't get the math correct or the appearance correctly, and I can't stop it from looping. Any suggestions? I'm not sure how to formulate the math so that it reflects quarters as 25 cents. Thanks in advance for any suggestions/ideas.




THIS IS WHAT THE OUTPUT SHOULD LOOK LIKE:

ENTER NUMBER OF QUARTERS INSERTED: 2
AFTER SPIN: ORANGE PLUM PLUM
YOU WIN: $1.00     YOUR BALANCE: $5.50

 
Tim Cooke
Marshal
Posts: 4044
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Isabel, welcome to the Ranch!

Let's take a look at the looping problem you mention for starters. In the code below I have simplified your program down to just the parts related to the while loop which may help you identify where the problem is:

Can you see how this code will never stop looping? Perhaps something needs to be done inside the loop body?
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

A few notes on posting here at CodeRanch:

* Write a descriptive subject line. 

* Do not use all caps.

I'll change this for you now, but in the future, your posts may be held up until you fix these things.
 
Isabel Munoz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and thank you.

So I tried inserting a break there but it didn't seem to stop the loop. I really don't know what else to do. I feel like it's staring me in the face and I can't see it. It becomes really frustrating when I run the program and it doesn't stop. So I can see where I need to make some formatting changes.

Any advice or assistance you can offer will be much appreciated.

Thank you again.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Isabel,

read Tims reply carefully. the code he showed you is:

Where in the body of this 'while' loop do you change this 'numOfQuarters'?

What I can remember of these slotmachines is that as soon as you press the 'play' button, your credits are reduced. So why not reduce the number of quarters as soon as this button is pressed (i.e. as soon as you enter the body of the 'while' loop again)? And, would it not be more logical if you test for this number of quarters to be > 0?

A question: have you been told about arrays yet?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!