# Random

• ### Question

• I have to make a program that gives a 10x10 table with all random numbers.

If the input number would be in the random table more then 3 times the backgroundcolor schould go red.

If it isnt in the list for +3 times the backround must be green.

//titel

Console.Title = "GokTabel";

//declaratie van de variabelen

int intrij, intkolom, intgokgetal, intgetal;
Random objrandom = new Random();
string struitvoer;
const int intaantal = 10;

//invoer

Console.WriteLine("Geef een getal");

//beginwaarde

struitvoer = "";
intgetal = 0;

//verwerking

for (intrij = 1; intrij <= intaantal; intrij++)
{
for (intkolom = 1; intkolom <= intaantal; intkolom++)
{
struitvoer = struitvoer + Convert.ToString(objrandom.Next(1,101)) + "\t";

if (intgetal == intgokgetal)
{

}
}
struitvoer = struitvoer + "\n";
}

//uitvoer

Console.WriteLine(struitvoer);

Wednesday, November 20, 2019 10:43 AM

### All replies

• This is what ive got now:

//titel

Console.Title = "GokTabel";

//declaratie van de variabelen

int intrij, intkolom, intgokgetal, intgetal, intrandom;
Random objrandom = new Random();
string struitvoer;
const int intaantal = 10;

//invoer

Console.WriteLine("Geef een getal");

//beginwaarde

struitvoer = "";
intgetal = 0;

//verwerking

for (intrij = 1; intrij <= intaantal; intrij++)
{
for (intkolom = 1; intkolom <= intaantal; intkolom++)
{
intrandom = objrandom.Next(1,101);
struitvoer = struitvoer + intrandom + "\t";

if (intrandom == intgokgetal)
{
intgetal = intgetal + 1;
}
}
struitvoer = struitvoer + "\n";

}

Console.ForegroundColor = ConsoleColor.Black;
if (intgetal > 3)
{
Console.BackgroundColor = ConsoleColor.Red;
Console.Clear();
}
else
{
Console.BackgroundColor = ConsoleColor.Green;
Console.Clear();
}

//uitvoer

Console.WriteLine(struitvoer);
Console.WriteLine(intgetal);

Wednesday, November 20, 2019 10:53 AM
• This looks like a homework assignment. So given your code, what is the question? It seems like your general code is correct with a cursory glance.

Michael Taylor http://www.michaeltaylorp3.net

Wednesday, November 20, 2019 2:54 PM
• Some hints.

You need a two-dimensional array (10x10) to hold the random numbers.

You need a one-dimensional array (length 10) to hold the frequency of each number.

The call to objRandom should return a number between 1 and 10, not 1 and 100. Place the result of this call into the two-dimensional array. Increment the appropriate frequency in the one-dimensional array by 1.

After you have finished filling the arrays, print the results in another loop.

Thursday, November 21, 2019 12:35 AM
• Hi JorenNOJUAHjebazd,

Thank you for posting here.

I basically agree with Ante Meridian's idea but there is only one point.

When there are 100 random numbers, if the number is limited to 1-10, basically no number will appear less than 3 times.

So limiting it to 1-100 would be a more appropriate choice.

And in this case, the one-dimensional array length should be 100.

Best Regards,

Timon

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Thursday, November 21, 2019 7:33 AM