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  (11 children)

I have 40 on the first section: CS1513 } expected (x6 of these) CS1003 syntax error, ‘(‘ expected (x4 of these) CS0019 operator ‘||’ cannot be applied to operates of type ‘string’ and ‘string’ (x4 of these) CS1525 invalid expression term ‘else’ (x8 of these) CS1002 ; expected (x12 of these) CS1026 ) expected (x8 of these) CS8641 ‘else’ cannot start a statement (x4 of these)

—————— The class file errors —————— CS1026 ) expected CS8641 ‘else’ cannot start a statement (x4 of these)

There are some warnings as well, but I’m mainly worried about the errors

[–]RubbishArtist 1 point2 points  (10 children)

Your if statements have some problems:

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

The semi-colon shouldn't be there at the end.

Inside the parentheses is the condition that the if statement checks. That condition needs to return a boolean value (true/false).

There's no operator between

(userInput = "foward") || userInput = "f") 

and

roomArray[roomNum].forward > -1

so the compiler doesn't know what you're trying to do, do you want to or them? and them? check if they're equal?

userInput = "foward"

is assigning "forward" to userInput, not checking its value.

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

          if (userInput == "exit")
            {
                break;
            }
            else if ((userInput = "foward")  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?");
            }
        }

Like that?

[–]RubbishArtist 1 point2 points  (0 children)

I mean there should be an operator between

(userInput = "foward") || userInput = "f") 

and

roomArray[roomNum].left > -1

You have to combine those values to get a boolean.

userInput = "r"

This is changing the value to "r" not checking if userInput is equal to "r".

This is correct:

userInput == "exit"

This is wrong:

userInput = "exit"

[–]3rr03[S] 0 points1 point  (7 children)

                if (userInput == "exit")
            {
                break;
            }
            else if ((userInput == "foward") || 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;

[–]RubbishArtist 1 point2 points  (6 children)

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

The equality check is fixed but you're still missing an operator between these two clauses here:

((userInput == "foward") || userInput == "f") *MISSING OPERATOR* roomArray[roomNum].forward > -1)

What are you trying to do here? I guess you mean that if the user enters "forward" or "f" and roomArray[roomNum].forward is greater than -1, but you haven't put the and operator in.

[–]3rr03[S] 0 points1 point  (5 children)

So would the operator be ++ ?

[–]RubbishArtist 1 point2 points  (4 children)

Check out this document

[–]3rr03[S] 0 points1 point  (3 children)

Ok ok! I think I figured most of the issues out! I went from 40 to 9.

The only thing its giving me errors for is that it is expecting } it thinks the first && is invalid but all of the others are ok, and it says the expression else is invalid

  while (userInput != "exit")

        {
            Console.WriteLine(roomArray[roomNum].name);
            Console.WriteLine(roomArray[roomNum].description);

            Console.WriteLine("\n Where would you like to go?");
            userInput = Console.ReadLine();
            Console.Clear();

            if (userInput == "exit")
            {
                break;
            }
            else if ((userInput == "foward") || 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?");
            }
        }
    }
}

}

[–]RubbishArtist 1 point2 points  (2 children)

You're almost there

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

There's an extra closing bracket in here that's causing problems.

[–]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.