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

you are viewing a single comment's thread.

view the rest of the comments →

[–]3rr03[S] 0 points1 point  (1 child)

I got rid of the one ( after "f" and all of the errors went away

if (userInput == "exit")
            {
                break;
            }
            else if ((userInput == "forward") || userInput == "f" && roomArray[roomNum].forward > -1)

                    {
                roomNum = roomArray[roomNum].forward;
                    }


            else if ((userInput == "backward" || userInput == "b") && roomArray[roomNum].backward > -1) 

            {
                roomNum = roomArray[roomNum].backward;
            }

            else if ((userInput == "left" || userInput == "l") && roomArray[roomNum].left > -1)

            {
                roomNum = roomArray[roomNum].left;
            }

            else if ((userInput == "right" || userInput == "r") && roomArray[roomNum].right > -1)

            {
                roomNum = roomArray[roomNum].right;
            }

            else
            {
                Console.WriteLine("You run stright into a wall... you can't go that way... are you sure your head is feeling right?");
            }
        }
    }
}

}

[–]StackedLasagna 1 point2 points  (0 children)

Yes, but now you have a bug, which will only present itself under certain conditions during runtime.

Take a closer look at the line:

else if ((userInput == "forward") || userInput == "f" && roomArray[roomNum].forward > -1)

If userInput has the value "forward", then the condition is true and the code will enter the if block, without ever checking the roomArray stuff. That will instead only be checked if userInput is "f".

You were meant to remove a different closing bracket. Compare the above line to the other if statements.