Can somebody explain why even when the number generated isnt the number in the if statement it still runs?
using System;
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
Mark Ransom12 pointsPosted Oct 9, 2006, 3:33 AM EDT
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
1 short reply
savan gandhi45 pointsPosted Oct 20, 2006, 1:41 AM EDT