• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unsure of how to propery loop my program  RSS feed

 
John Vorona
Ranch Hand
Posts: 48
Java Mac OS X Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I wrote a program which is displays a simple subtraction equation and waits for the user input. If the user provides the correct solution, it displays the boolean "true". If the user provides an incorrect solution, it displays the boolean "false" and provides the correct solution.
The problem I have is that I want the program to loop and provide another equation if the user provides the correct solution. If the user provides the incorrect solution, I want the program to terminate.

Here is my code:



Any ideas of how to loop this ?
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only a few minimal changes need to be made. I suggest using a while loop that checks the validity of answer. Upon answer's declaration, initialize it to true so that the program enters the while loop the first time.
 
John Vorona
Ranch Hand
Posts: 48
Java Mac OS X Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see, I know this is asking for a lot, but I am new to loops and programming in general, if its not troubling could you edit my code and post the updated version here?
 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nazar Buko wrote:I see, I know this is asking for a lot, but I am new to loops and programming in general, if its not troubling could you edit my code and post the updated version here?

Sorry but that's not how we work here. We will guide you but we won't just do it for you.
Read Joel's post carefully and see if you can implement what he has suggested. If you get stuck, post the code and someone will help you.
 
John Vorona
Ranch Hand
Posts: 48
Java Mac OS X Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem, I was wondering if anyone would. I learn best like this, but thank you nonetheless.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to learn to program is to write the code yourself and not to just look at other peoples code. It's harder to write it yourself but you definitely learn more by doing it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!