0

So I have myself an array like this one:

int masterNumber = randomNumber.Next(1, 7);
        int childNumber;
        int[] fieldArray = new int[] {masterNumber, childNumber = randomNumber.Next(1, 7)};

So now i'd like to write the master number to my console ONLY ONCE using Console.WriteLine(); and I'd like to write the random childNumber 99 times to the console, each childNumber with it's own value between 1 and 7. How would I do this?

unknown
  • 25
  • 6
  • Are you looking for a method to populate the `fieldArray` with that master number and `99` random number or you just want to print the same `childNumber` 99 times? – sujith karivelil Feb 28 '17 at 06:15
  • What about just using `Console.WriteLine(fieldArray[0])` and then using a `for (int i = 0; i < 99; i++) Console.WriteLine(fieldArray[1])` ??? – Alisson Reinaldo Silva Feb 28 '17 at 06:15
  • I'm looking to populate the fieldArray with my master number and 99 random numbers yes. – unknown Feb 28 '17 at 06:16
  • Have not try any sample, you can start here C# For Loops https://www.dotnetperls.com/for – Hüseyin Burak Karadag Feb 28 '17 at 06:16
  • Take a read in [looping](http://stackoverflow.com/documentation/c%23/2064/looping#t=20170228062156478471) and you might find a way to do this. – Alisson Reinaldo Silva Feb 28 '17 at 06:22
  • Linked http://stackoverflow.com/questions/10696861/filling-a-array-with-random-numbers-between-0-9-in-c-sharp (as dup) shows how to fill such array with all random numbers. Presumably you should be able to set first item to whatever you want afterwards. If that is beyond your current abilities - try asking new question "how to set first element of an array" (no guarantees of result so :) ) – Alexei Levenkov Feb 28 '17 at 06:24

1 Answers1

0

Why you want to use fieldArray if you have "masterNumber" & "childNumber". But I think, you can do it in this way...

Random randomNumber = new Random();
int masterNumber = randomNumber.Next(1, 7);
int childNumber;
int[] fieldArray = new int[] { masterNumber, childNumber = randomNumber.Next(1, 7) };

Console.Write("Master Number " + masterNumber);
int i = 0;
while (i < 99)
{
   Console.Write("Child Number " + childNumber);
   Console.WriteLine(i);
   i++;
}
J.SMTBCJ15
  • 471
  • 6
  • 20