Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problems with a C# switch statement

I am making a paper scissors rock game and am receiving the following error:

Cannot implicitly convert type ‘int’ to ‘system.random’

namespace Rock__Paper__Scissors_CSNET
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This is a Rock, Paper, Scissors game. Enter your choice below");
            Console.WriteLine("1. Rock");
            Console.WriteLine("2. Paper");
            Console.WriteLine("3. Scissors");
            string userInput = Console.ReadLine();
            Random Computer_Random = new Random();
            int randy = Computer_Random.Next(1, 4);
            switch (Computer_Random)
            {
              case 1:
                    break;

                case 2:
                    break;

                case 3:
                    break;
            }
            
        }

    }
}

What am I doing wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use switch (randy) instead.

namespace Rock__Paper__Scissors_CSNET
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This is a Rock, Paper, Scissors game. Enter your choice below");
            Console.WriteLine("1. Rock");
            Console.WriteLine("2. Paper");
            Console.WriteLine("3. Scissors");
            string userInput = Console.ReadLine();
            Random Computer_Random = new Random();
            int randy = Computer_Random.Next(1, 4);
            switch (randy)
            {
              case 1:
                    break;

                case 2:
                    break;

                case 3:
                    break;
            }
            
        }

    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading