dimanche 16 août 2015

Get the total of a number in a loop in C#

My program generates 2 random numbers from 1 - 6.
The program loops ten times to check if numb1 matches numb2, and if it does, the program displays the number matched.

How can i get the total of numb1, for example if the out put was:

Output:

i value:      2
numb1 value:  1

i value:      3
numb1 value:  2


i value:      10
numb1 value:  5

"The total of numb1 is: 8" <-- how can i get the total?


  static void Main(string[] args)
    {


        for (int i = 1; i < 11; i++)
        {
            int numb1 = anyNumber();
            int numb2 = anyNumber();

            if (numb1 == numb2)
            {
                Console.WriteLine("i value:      " + i);
                Console.WriteLine("numb1 value:  " + numb1);
                Console.WriteLine();
            }

        }
    }


    static Random randNumb = new Random();
    static int anyNumber()
    {
        return randNumb.Next(1, 7);
    }




Aucun commentaire:

Enregistrer un commentaire