This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Ok, i've been trying since like 2 days ago to solve this problem, but i havent been able to do so. this is the error i get:
As you can see the game ends when i enter a number higher than the number of marbles. however, i dont want the game to end, i want it ask the question again, until the user enters a number thats is not greater than the number of marbles, and that is not greater than the number of marbles divided by 2. this is the code i have so far, i've tried making a boolean method but it always escape the program, i want it to repeat the question:
this is the code i have so far:
thanks for the support [ April 01, 2006: Message edited by: apollo abel ]
To prevent the exception, you need something like this:
But the real problem is that you probably want to constrain numMarbles to some number between min and the number of marbles actually left. For example:
As far as exiting the loop - I confess I haven't looked carefully at your code. It can definitely be simplified ... but as far as I can tell, once you compute the random value and pcMarblesTaken correctly, then it looks like numMarbles should eventually go down to zero and the loop exit. So you should be OK...
'Hope that helps .. PSM [ April 01, 2006: Message edited by: Paul Santa Maria ]
Paul M. Santa Maria, SCJP
Joined: Mar 31, 2006
Ok, the code now its done - well not really, is not an efficient code - here it is: