Start with the easy one:
Quote:
there is an error with the else term?
Look at your code closely:
if ((user != "Anders") || (pass != 1234));
See that semicolon?
That ends the
if
block, so the following statement is executed regardless of the
if
condition. And because of that, the system can't find an
if
to match the
else
and complains.
Remove the semicolon:
if ((user != "Anders") || (pass != 1234))
{
Console.WriteLine("Logged out!");
}
else
{
Console.WriteLine("Login successful");
}
And your error will disappear.
BTW: it's a very good idea to always use curly braces, even when you don't need them - it saves a lot of grief later on if you add a line. With the braces, it's obvious that the line need to be inside them, without? Not so clear and can lead to mistakes.
Other problem:
Quote:
"Anders" does not exist in a current context,
Correct, it doesn't. Again, look at the code:
if ((user != Anders) || (pass != 1234))
Anders
is not quoted, so it's a variable name, not a string value. There is no variable called
Anders
in that method, so the system doesn't know what you mean and complains.
Later on in your code, you use a string:
while (((user != "Anders") || (pass != 1234)) && (counter != 3));
So at a guess, you want to use double quotes around
Anders
in both cases:
if ((user != "Anders") || (pass != 1234))