Link to home
Create AccountLog in
Avatar of Computer Guy
Computer Guy

asked on

URGENT!!!!: Issue with Java Counter

Hi,

I have this code here that runs an guessing game for flags.

The user has 3 tries to guess the correct flag. If they guess it correct on the first try, they get 3 points and since it was only 1 guess, I added a counter (numGuesses) to count the number of guesses on the first try they have correct.

I am having an issue. See the method around line 261 (private void submitGuess(Button guessButton) )

The counter seems to be inaccurate and don't know what I did wrong? Either on the last try it does not add the numbers correctly or on the first try.

Where am I messing up?

Thanks!
source.java
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

So what result do you get, and which var are you referring to as being wrong?
Avatar of Computer Guy
Computer Guy

ASKER

CorrectFirstTry is short we of the time and the same with points.  Not sure if it is calculating the last since it is a loop of 10.
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
My thought was numGuesses would be less than 3. Then it resets with next question.

If the first try is correct the number guess is 1. And then correctForstTry would be +1 and points would be 3.
I tried adding that code and it does not output in the console. This is an android app but I still don't see it on the console.
We don't really know what the problem is meant to be doing - so it's hard to help you debug it.  It's clear you get points for correct answers, but exactly how many points and when isn't clear.

If you want help, I think you need a clearer explanation of exactly which variables have the wrong values and when.

Did you try my suggestion of logging the value of "numGuesses" and watching how it changes with each guess?
What values do you get, what points and what do you expect?
I am pleased doug made the point about numGuesses as that was my first thought. Whether it's the problem or not, it should not be inside any if statement afaics.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account