I am trying to make a 'guess the password' program but it is not working and I am not sure as to why. Basically, the password is Apple and the user has to try and guess Apple. If they guess it correctly, the program should say "That is correct' (that is not working) but if they guess it incorrectly the program will provide a hint and keep on giving the user that hint until they guess it correctly. Here's my code: (Help is appreciated, thanks!)
Mostly works for me. You have a bit of broken logic at line 27. You print out "it is a fruit" inside the if() statement, that is good. However you also print "Guess again!" and get the new password1 value inside the if() statement, that is bad. What if you want to enter a new guess without getting a hint?
Some comments about the original code:
1. It is better to avoid unecessary comments like "variables". It's ok in the beginning of learning but avoid it as quickly as you can.
2. Remember to close the Scanner! (input.close())
3. Examine the starting and ending points of your loops carefuly.
Now, for the Java pros, I am asking a question: do you have a better code for this one, a cleaner one? I'm asking cause sometimes I don't know if it's good practice to use a control variable for the loop, since it's an additional variable. In this case, it is the boolean 'guessed'.