mardi 18 octobre 2016

C# IF / Console.Write need solution

I'm trying to write out random numbers in an interval with IF command and use different color at each condition.

int x = -50, y = -38;
int min = 999, max = -999, sum = 0;

Random rnd = new Random();
int[,] t = new int[20, 20];
for (int i = 0; i < 20; i++)
{
    for (int j = 0; j < 20; j++)
    {
        t[i, j] = rnd.Next(x, y);

        if (min > t[i, j])
            min = t[i, j];

        if (max < t[i, j])
            max = t[i, j];

        sum += t[i, j];

        if ( t[i, j] == min)
            if (t[i, j] == (min + 1.0 * (max - min) / 5.0))
        {
            Console.ForegroundColor = ConsoleColor.DarkBlue;
        }

        if (t[i, j] == (min + 1.0 * (max - min) / 5.0))
            if (t[i, j] == (min + 2.0 * (max - min) / 5.0))
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
            }

        if (t[i, j] == (min + 2.0 * (max-min) / 5.0))
            if (t[i, j] == (min + 3.0*(max-min) / 5.0))
            {
                Console.ForegroundColor = ConsoleColor.Magenta;
            }

        if (t[i, j] == (min+ 3.0 *(max-min) / 5.0))
            if (t[i, j] == (min + 4.0 * (max - min) / 5.0))
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }

        if (t[i, j] == (min + 4.0 * (max - min) / 5.0))
            if (t[i, j] == max)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
            }
        Console.Write(" " + t[i, j]);

        //Console.Write("{2} ", i, j, t[i, j]);
    }
    x++;
    y++;
}
Console.WriteLine("Min: " + min);
Console.WriteLine("Max: " + max);
Console.WriteLine("Sum: " + sum / t.Length);
Console.ReadKey();

The running program only write out dark red numbers.

Aucun commentaire:

Enregistrer un commentaire