# I attempted to solve The 'Tries left' problem my self. Did I do this wrong? Please check and let me know

I haven’t yet seen Ben’s solution to this yet however I had a go at it in the simplest way I could think of it. I would greatly appreciate if someone could tell me in detail if anything I do is bad practice and why it is so.

I firstly changed the prototyping of the GetGuess() function in the main.cpp file so that it accepts an int as an argument.

I then declared an int of ‘TriesLeft’ which calls the GetCurrentTry() from the BCGame class to get the amount of tries a player is allowed.

The value of which I set in the class:

I then wrote the following code so that every time the player makes a guess, 1 try is taken away from the maximum tries allowed.

I then passed ‘TriesLeft’ to GetGuess()

Which displays the updated value with each iteration of the loop:

it works perfectly. Would just appreciate some feed back.

UPDATE: I am aware that I used ‘GetCurrentTry’ from the class instead ‘GetMaxTries’. Let’s assume for the sake of the discussion that I have used GetMaxTries.

This is an interesting solution to what you’re trying to accomplish. I know that the whole idea was to implement using the Getter methods from the Game Class, but you really don’t need TriesLeft here. You already have ‘i’, which is effectively a count of what try you are on, and MaxTries. You can easily do some math in place to get your TriesLeft.

`int TriesLeft = MaxTries - i + 1;`
The reason why I put a +1 on the end of this is because we haven’t used the try that ‘i’ says we’re on.

A concept change that you could do is to change ‘i’ so that it is a count of how many tries you have used instead of what try you’re on. You could then just subtract that number from MaxTries to get the number of tries left. You also wouldn’t have to worry about that +1 on the end.

I think I’ll leave that there for now.

1 Like