mercredi 7 octobre 2015

Adding the sum of two randomly generated numbers (using arrays)

class Program
{
    const int ROLLS = 51;
    static void Main(string[] args)
    {
        Random r = new Random();
        int sum = 0;
        int[] dice1 = new int[ROLLS];
        int[] dice2 = new int[ROLLS];

        for (int roll = 0; roll <= 50; roll++)
        {
            dice1[roll] = GenerateNum(r);
            dice2[roll] = GenerateNum(r);
            Console.WriteLine("ROLL{0}: {1} + {2} = sum goes here", roll+1, dice1[roll]+1, dice2[roll]+1);
        }
    }

    static int GenerateNum (Random r)
    {
        return r.Next(1, 7);
    }
  }
}

So what I have is two arrays to store two different int values that are randomly generated and what I am trying to achieve is the sum of these two randomly generated int values.

Upon execution it should display: Roll 1: (random number) + (random number) = (sum of the two random numbers)




Aucun commentaire:

Enregistrer un commentaire