• Post Reply Bookmark Topic Watch Topic
  • New Topic

While loop program  RSS feed

 
Dania Perez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to make a program that whenever the user inputs a number it is subtracted from the number of tokens, which they start with 100, and the program keeps going until the user has no more tokens, meaning zero tokens. I tried doing it and I know I have mistakes because when I run the program I get a loop of "How many tokens per game?" and a number over and over again.
 
Carey Brown
Bartender
Posts: 3009
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your while conditional is based on userTokens which does not change in the body of the loop. Only tokenTotal changes.
 
Dania Perez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So then I wrote it wrong?
 
Carey Brown
Bartender
Posts: 3009
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you get a pencil and paper and play computer. Keep track of the values in userTokens and tokenTotal as you go through several iteration of your loop. I think you'll quickly see the problem.
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!