Junilu Lacar wrote:
Damien O Sullivan wrote:What should I use so to get the program to repeat the same question again?
The quickest thing to do is right now (although it doesn't do anything to make your code cleaner) is to add something that says:
if (answer is not the right one)
// ???
after the user enters the wrong answer again. The ??? needs to be some statement that can affect whether or not the while-loop will continue to execute.That's really all you're missing right now. Again, it's not pretty but it will work.
Edit: I take that back. I see you got it to work somewhat. So all you want to do now is to make it go back and ask the same question again. Then what's the point of putting logic to make it ask a second time? Do you want to keep asking the same question until they get the correct answer or do you only want to give them two chances to get it right?
Damien O Sullivan wrote:I want to keep asking them the same question until they get it right, then when they do, I want to generate a new question for them.
Junilu Lacar wrote:
Damien O Sullivan wrote:I want to keep asking them the same question until they get it right, then when they do, I want to generate a new question for them.
How do they stop if they get tired of playing?
Damien O Sullivan wrote:I haven't tried to code that part yet, stopping the game wasn't mentioned in the brief but I want to try and get around to that bit eventually. Now I'm just having trouble with getting the question to repeat until its answered correctly.
Junilu Lacar wrote:
Damien O Sullivan wrote:I haven't tried to code that part yet, stopping the game wasn't mentioned in the brief but I want to try and get around to that bit eventually. Now I'm just having trouble with getting the question to repeat until its answered correctly.
I would have started with the ending the game logic first but that's just me.
Anyway, you have to do a bit of a mind shift. Instead of trying to figure out a way to force execution back to where you want it to go, go with the natural flow of the program and tweak something else. Like I said, you need some logic that controls whether or not you're going to generate a new set of numbers. So when you get to the part where you're asking the question, either you're asking a new question or you're asking the same question as the last time you executed the loop.
Damien O Sullivan wrote:The frustrating part is that when I answer incorrectly once and then answer correctly the second time, the code runs fine. The problem is when it I get the same question wrong more than once.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:Whilst I agree with Winston, one of the problems why this topic is halfway page 2
is that there have been quite some repliers, each stumbling over their own feet
in the hurry to supply yet another reply, with all the good intententions of the world...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Damien O Sullivan wrote:Just so you all know, I'm after sorting it anyway, threw in a second while loop inside the if statement
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Consider Paul's rocket mass heater. |