-3

enter image description here

Im working on HighLow Game. Im trying to create a method that will PlayAgain if User want to play again ,but i'm getting this Bug saying. no all code path return a value. when i click the debug button it says replace the PlayAgain with a property . when i click on the automatic debug it build only get on the bottom ,but still with another bug, i delete and write { get; set; } next to PlayAgain everyCode turn errors. please can anyone help

    public static void Main(string[] args)
    {

        bool play = true;
        while (play)
        {
            //Instatiate
            HighLow.Play();

            //Play Again?
            play = PlayAgain();
        }
        Console.WriteLine("s");
    }
    public bool PlayAgain { get; set; }
    private static bool PlayAgain()
    {
        //Ask user

        HighLow.Footer();
        Console.WriteLine("Would you like to play again?[Y/N]");
        //Catch resp
        string userchoice = Console.ReadLine().ToUpper();
        //Condition 
        if (userchoice == "Y")
        {
            //clean 
            Console.Clear();
          
            Main(null);
        }
        else
        
        {
           
            Console.WriteLine("Thanks for playing, have a great day!");
            Environment.Exit(0);
        }
    }
}

}

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • Please figure out which language you are using and edit your post accordingly. Code from C++ won't necessarily compile in C, and most code from C/C++ won't compile in C# and most C# code won't compile in C or C++. If you're simply tagging all these languages for more views, then you're annoying people by tagging the language tag they follow against code/a question for a different language and thereby earning downvotes. – ProgrammingLlama Oct 07 '20 at 05:57
  • What is the error? The error code on this one should be clear. This one should be a "_CS0120, An object reference is required for the nonstatic field, method, or property PlayAgain_". – Drag and Drop Oct 07 '20 at 06:11
  • For the restarting the application you should add a simple loop. You should not add I/O in a getter. Getting the value should be simple operation: a computation, accessing value of an other field, some concatenation. But not An action that require user input and can lead to exception. When you get X in your fridge, it's simple. You don't expect the fridge to blow up or have to wait the door open till the delivery man fill it up. – Drag and Drop Oct 07 '20 at 06:17

1 Answers1

0

All that means is that the method that is supposed to return a value is not returning anything. It is a bit hard without seeing your code but you need to specify what value is being returned by your method for starters and if you have then you need to return a value with the return statement at the end of the method. Easy one!

Soliman Soliman
  • 159
  • 1
  • 4
  • 17