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
JavaAndroidProgramming

Avatar of undefined
Last Comment
krakatoa

8/22/2022 - Mon
krakatoa

So what result do you get, and which var are you referring to as being wrong?
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
dpearson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Computer Guy

ASKER
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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Computer Guy

ASKER
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.
dpearson

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?
krakatoa

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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.