guessing game question, calculate games won?

I cannot get this to accurately calculate the percent of games won. I tells me 0% even if i did win a game, suggestions?
,
Last edited on
As shown in your code, using the same names for different variables in different scopes can lead to bugs.
Your main function and PlayGame function uses the same names for variables, and because of that you thought that they are holding the same value. They're not. gamesWon in PlayGame() is indeed increasing, but nothing is done with value of this.
And inside main(), gamesWon value isn't changed, but it's used.
I'd suggest you changing these variable names, or even better - redesigning your code. It surely could be done clearer. :)

Cheers!
But shouldn't gamesWon being a static int allow the value to be used outside of PlayGame function?
Don't use the same variable names. It's distracting for you and potential co-worker.
This said, new variable shadows the previous one. As you see on your code, it doesn't work properly :)

Also, even if it was global, you shouldn't use global variables - they're not really good.

Cheers!
Last edited on
nvm
Last edited on
Topic archived. No new replies allowed.