• Post Reply Bookmark Topic Watch Topic
  • New Topic

Loop Not working.  RSS feed

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey! For an assignment I have to do I am having some issues with the while loop. The user is suppose to print the number of questions they will answer correctly. If the user answers a question incorrectly the user MUST keep answering questions until he gets the amount of number questions correctly as he stated he will get correctly. Here is my code!

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is code breaking and what's the error?
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I removed the error. But If I change the count in the else statement to numCorrect it will keep printing out questions even if the user has answered enough question
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your while statement looks like this:

Where are you testing numCorrect?
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is better to use a Random object to get those ints than doing arithmetic with Math#random.
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My professor want me using numCorrect instead of count. I am so close to completing this.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!