Im creating a random number generator to simulate the rolling of three dice. I've put together code (not sure how correct it is) and for some reason instead of displaying random numbers between 1 and 7 it just displays 0's. Can anyone help me to fix this problem?
Thanks
Heres the code
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
RollingDice rd = new RollingDice();
Console.WriteLine("Rolling count:{0}", rd.rollingCount);
Console.Write(rd.first);
Console.Write(rd.second);
Console.Write(rd.third);
Console.ReadKey();
}
}
class RollingDice
{
public int first;
public int second;
public int third;
public int rollingCount;
Random r = new Random();
public void CallBackFunction(Object stateInfo)
{
first = r.Next(1,7);
second = r.Next(1,7);
third = r.Next(1,7);
Console.Write(first);
Console.Write(second);
Console.Write(third);
Console.Write("\b\b\b");
rollingCount++;
if (first == second || first == third || second == third)
{
Console.Write("you scored:");
}
if (CheckIfExistTwoNumberEqual())
{
}
}
bool CheckIfExistTwoNumberEqual()
{
return (first == second || first == third || second == third);
}
}
}
Question
woolm
Hey all
Im creating a random number generator to simulate the rolling of three dice. I've put together code (not sure how correct it is) and for some reason instead of displaying random numbers between 1 and 7 it just displays 0's. Can anyone help me to fix this problem?
Thanks
Heres the code
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { RollingDice rd = new RollingDice(); Console.WriteLine("Rolling count:{0}", rd.rollingCount); Console.Write(rd.first); Console.Write(rd.second); Console.Write(rd.third); Console.ReadKey(); } } class RollingDice { public int first; public int second; public int third; public int rollingCount; Random r = new Random(); public void CallBackFunction(Object stateInfo) { first = r.Next(1,7); second = r.Next(1,7); third = r.Next(1,7); Console.Write(first); Console.Write(second); Console.Write(third); Console.Write("\b\b\b"); rollingCount++; if (first == second || first == third || second == third) { Console.Write("you scored:"); } if (CheckIfExistTwoNumberEqual()) { } } bool CheckIfExistTwoNumberEqual() { return (first == second || first == third || second == third); } } }Link to comment
Share on other sites
3 answers to this question
Recommended Posts