1

I have problem with my code:

using System;
using System.Threading;

namespace popo
{
    public class Human
    {
        public static void Main()
        {
            Console.Write("Login: ");
            public string LogInput = Console.Read();
            if(LogInput=="ADMIN")
            {
                System.Console.Write("Password: ");
                public string PassInput = Console.Read();
                if(PassInput == "ADMIN")
                {
                    System.Console.Write("L");
                    Thread.Sleep(1000);
                    System.Console.Write("O");
                    Thread.Sleep(1000);
                    System.Console.Write("G");
                    Thread.Sleep(1000);
                    System.Console.Write("G");
                    Thread.Sleep(1000);
                    System.Console.Write("E");
                    Thread.Sleep(1000);
                    System.Console.Write("D");
                }
            }
        }
    }
}

When Im trying to compile it, compiler says:

Mm.cs(10,38): error CS1513: } expected
Mm.cs(12,13): error CS1519: Invalid token 'if' in class, struct, or interface member declaration
Mm.cs(12,24): error CS1519: Invalid token '==' in class, struct, or interface member declaration
Mm.cs(14,37): error CS1519: Invalid token '(' in class, struct, or interface member declaration

printf
  • 325
  • 1
  • 7
noname
  • 23
  • 3
  • 1
    Post your code as `code text`, not images. – pkamb Aug 28 '20 at 23:13
  • Im not able to do that cause then it's mostly code and i can't send it, – noname Aug 28 '20 at 23:33
  • Just copy and paste the text shown in your images into this question. If there needs to be more text, then please better describe your problem using more non-code words. – pkamb Aug 28 '20 at 23:39
  • 1
    fixed. sorry im new here. – noname Aug 28 '20 at 23:47
  • Does this answer your question? [Invalid token '=' in class, struct, or interface member declaration c#](https://stackoverflow.com/questions/36179921/invalid-token-in-class-struct-or-interface-member-declaration-c-sharp) – pkamb Aug 29 '20 at 00:00
  • No. first error is on line 10 "} expected" . 10th line is console.writeline. and when im removing 10th line it says that } is expected in 9 – noname Aug 29 '20 at 00:03
  • Remove `public` in the declaration of `LogInput` and `PassInput`, and also replace `Console.Read()` by `Console.ReadLine()`. That is, you should have `string LogInput = Console.ReadLine();` and `string PassInput = Console.ReadLine();`. – printf Aug 29 '20 at 00:22
  • Don't forget to thank the person who answered by upvoting and accepting their answer. – pkamb Aug 29 '20 at 00:51

1 Answers1

1

Inside your Main() function, the local variables LogInput and PassInput must be declared without the public keyword. Also, replace Console.Read() by Console.ReadLine(). Thus your Main() should look like this:

public static void Main()
{
    Console.Write("Login: ");
    string LogInput = Console.ReadLine();
    if(LogInput=="ADMIN")
    {
        System.Console.Write("Password: ");
        string PassInput = Console.ReadLine();
        if(PassInput == "ADMIN")
        {
           // further as you had it...
        }
    }
}

Check this DotNetFiddle.

printf
  • 325
  • 1
  • 7