• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unsure of how to propery loop my program

 
Ranch Hand
Posts: 48
Mac OS X Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic