|
As both you and I said, the result cannot grab the input from inside the try and simply initializing guess without a value will not work. Now, as i stated, I can use int guess = 0; where you have int guess . My issue is in my code for some strange reason if I do that, after the user enters a guess which gets caught in the catch, no matter what they enter directly after, it automatically replaces it with a 0.
The reason I included that return Guess.guess(); is because my professor wants the players turn to continue, without adding to the count, until they enter the proper integer.
For example, in a two player game this is how it would initialize:
1. User 1 enter: d (or any string/float)
2. Output: Error, must be an integer, re-enter (or whatever my output in the catch is)
3. User 1 enter: 4
4. User 2 enter: 90
5. Output: User 1, guess cannot be below 1 (if the user enters 0 or a negative. In this case the guess, for some reason, is given the value 0 and cancels out the value 4 which user 1 enters the second time)
6. Output: User 2, guess is (either too low or too high depending on their number)
Then in 7 and so on users re enter guesses until a winner is chosen.
Believe me, I'm still only a novice at coding but I have tried many different solutions including making the try catch into a try string and then just channging the string to an int before it is returned, but that did not work either. If anyone could even give me a more effective try catch that would work for this sort of thing that would be okay too.
:edit: I would hate to do this, but if you would like (to better assist in the solution process) I can upload the entirety of my program here so you can see exactly what I mean. I've tried using debugger to see exactly where the problem is, but I just can't put my finger on it.
Last edited by ItsMeSean; 10-21-2011 at 04:58 AM..
Reason: Helpfullness
|