5
Answers

Random Class

kindra dragon

kindra dragon

16y
2.4k
1
Hey all,
I am having trouble with one of my programs im trying to make with random class. I am a begginer of C# and was wondering if someone can point me in the right direction.

            Random x = new Random();
            int randomNumber = x.Next(1, 5);
            labelNumber.Text +=
                randomNumber + "";

That is my code to generate a number so I can assign it to an if statement eg.

          if ( labelNumber = 1)
             outputBox.Text = "You won"
etc. etc.
I cant get it to work because it says
Error    1    Cannot implicitly convert type 'int' to 'System.Windows.Forms.Label'   
Error    2    Cannot implicitly convert type 'System.Windows.Forms.Label' to 'bool'   

If anyone can help me I would really appreciate it.

Thanks!!


Answers (5)