• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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: 5459
147
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: 61773
193
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!