So I am new to C# and I'm making a basic program which assigns random values to an array of 6.
private void button1_Click(object sender, EventArgs e)
{
tbxA.Clear();
tbxB.Clear();
int[] number = new int[6];
Random m = new Random();
for (int i = 0; i < 6; i++)
{
number[i] = m.Next(0, 4);
tbxA.AppendText("" + Convert.ToString(number[i]) + "\n");
}
int sum = number.Sum();
if (sum > 8)
{
tbxB.AppendText(" " + sum);
}
}
This will display the randomly generated array numbers 1-6 in the textbox A and if their total sum is over 8 it will display the sum in the textbox B.
However, what I want to do here is so the numbers in the array only displays in textbox A when their sum is greater than 8. If their total sum is less than 8, new numbers should automatically be generated for the array until it matches the requirement sum > 8.
I have tried to use another for loop with everything inside as well as ifs inside it, but it causes the program to crash.