Can somebody explain why even when the number generated isnt the number in the if statement it still runs?
using
using
System.Collections.Generic;using
System.Text;namespace
ConsoleApplication1{
class Program{
static void Main(string[] args){
Random r = new Random(); int scores = r.Next(1, 7);System.
Console.WriteLine("{0}", scores);System.
Console.ReadLine(); if (scores == 4) ;{
System.
Console.WriteLine("=4");System.
Console.ReadLine();}
}
}
}
Thanks
savan gandhiPosted Oct 20, 2006, 5:41 AM
Mark RansomPosted Oct 9, 2006, 7:33 AM
It doesn't work because you put a semicolen after the If statement declaration:
...
if (scores == 4) ;
{
System.Console.WriteLine("=4");
System.Console.ReadLine();
}
...
Take out the semi colen, so that the snippet looks like this:
...
if (scores == 4)
{
System.Console.WriteLine("=4");
System.Console.ReadLine();
}
...
And you should be fine.
Later
Mark