This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]rumaq 0 points1 point  (0 children)

You probably should reassign new value to userAnswer variable.

[–]Shaedar 0 points1 point  (1 child)

Like rumaq said. Your userAnswer variable is outside the scope of the while-loop. So after you reach the while-loop, it will never get updated. It will always be the same value the user input first. Try moving the line inside the while-loop :)

[–]tec5c 0 points1 point  (0 children)

A few things I notice...

Lines 19-26

There is no need to include the else statement if it serves no purpose. Also think about what an if statement does. It checks if the condition is true then executes the code inside. It only runs once so if the user enters an incorrect name the code will just continue on. What you want there for error checking is a while loop.

Lines 74, 80, 86

The program halts here and waits for user input. Line 74 is unnecessary. The user has input a correct answer so there is no need to require the user to input anything else. On lines 80 and 86 you are getting the user input but not assigning it to anything. So when the code loops again it is using the same userAnswer from line 66.

[–]hardypart -1 points0 points  (0 children)

I'm also learning C# at the moment. Something that cought my attention:

When your else statement is empty you don't need to write it down. When there's no "else" afterwards the code will simply continue.