I am writing an application in C# for a class project and having troubles writing out the results. It is supposed to simulate rolling a pair of dice 100 times and writing out the results to a sequential file. When I run the code, the loop writes out only one result (i.e. 5,2) for all 100 records. Any ideas on why? When I place a break point at the write statement, it shows the values have changed, but nothing seems to be writing.
private void button1_Click(object sender, EventArgs e)
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"c:\temp\dicerolls.txt", false))
for (int i = 0; i < 100; i++)
{
int dice1 = 0;
int dice2 = 0;
Random rnd = new Random();
dice1 = rnd.Next(1, 7);
dice2 = rnd.Next(1, 7);
int result = dice1 + dice2;
string display = Convert.ToString(result);
string die1 = Convert.ToString(dice1);
string die2 = Convert.ToString(dice2);
lblDie1.Text = "Die 1 = " + die1;
lblDie2.Text = "Die 2 = " + die2;
lblResult.Text = "Total = " + display;
file.WriteLine(Convert.ToString(dice1) + ","+Convert.ToString(dice2)+"\n");
}
}