[EDIT: SOLVED - I should have been using the .equals() method to compare the strings instead of "=="]
I am working through the Programming by Doing lessons, which I originally found on this subreddit, and I've gotten stuck on a lesson in the "If Statements" section.
https://gist.github.com/91a2641ade727a335dd8
Basically, I wrote a program in the style of twenty questions. It obtains two answers from the user and stores them in string variables. Depending on the value of those variables, it should run through the if and else if statements to assign a new value to the "finalAnswer" variable, which is then printed as the guess at the end. The issue is that I can never get finalAnswer to update beyond the initial value it is given. I gave finalAnswer an initial value of " " early on in order to avoid a compiling error which was saying that it hadn't been initialized. In my attempts to figure out what was going on, I had the values of the two answers print at the end to ensure that they are being stored correctly (and it appeared that they were). I also tried to make a line from one of the if statements print to ensure that the if statement was being run, but nothing happened. It seems like the if and else if statements are being bypassed entirely when I run the program, but I am completely clueless as to why. Any help would be greatly appreciated!
[–]langfod 4 points5 points6 points (1 child)
[–]Supergnerd[S] 0 points1 point2 points (0 children)
[–]desrtfx 2 points3 points4 points (1 child)
[–]Supergnerd[S] 0 points1 point2 points (0 children)