-3

I am new to c# and encountered a slight problem when trying to display the output

When I type in: Help,? or stats no output is shown

class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Type 'Help' to see list of commands");
        Console.ReadLine();
    }

    private static void ParseInput(string input)
    {
        if (input.Contains("help") || input == "?")
        {
            Console.WriteLine("Available commands");
            Console.WriteLine("====================================");
            Console.WriteLine("Stats - Display player information");
            Console.ReadLine();
        }
        else if (input == "stats")
        {
            Console.WriteLine("Current hit points:");
            Console.ReadLine();
        }
    }
}

I already added Console.ReadLine(); Still nothing.

Tried to search for other threads like Console.WriteLine does not show up in Output window and Why doesn't Console.Writeline, Console.Write work in Visual Studio Express?

Community
  • 1
  • 1
Jami Rocha
  • 11
  • 3

2 Answers2

0

You have to call the ParseInput function.

public static void Main(string[] args)
{
    Console.WriteLine("Type 'Help' to see list of commands");
    var input = Console.ReadLine();

    ParseInput(input); // call the function to process your input
}

private static void ParseInput(string input)
{
    if (input.Contains("help") || input == "?")
    {
        Console.WriteLine("Available commands");
        Console.WriteLine("====================================");
        Console.WriteLine("Stats - Display player information");
        Console.ReadLine();
    }
    else if (input == "stats")
    {
        Console.WriteLine("Current hit points:");
        Console.ReadLine();
    }
}
whymatter
  • 755
  • 8
  • 18
0

you should use the value of ReadLine

var value =   Console.ReadLine();
ParseInput(value);

also to remove being aware of case use ToLower, that way typing "Help" will trigger the logic you want.

private static void ParseInput(string input)
{
   input = input.ToLower();
   ....
}
Shachaf.Gortler
  • 5,655
  • 14
  • 43
  • 71