dimanche 1 mars 2020

C# Trouble getting my conditional statement to run true

My conditional statement for my user input doesn't seem to be evaluating correctly. If a user enters an input over 100 or under 1 it should show the error message. I've been playing around with it, swapping out variables and can either get all errors, no errors, or crash the program. Any help is appreciated!

            double sum = 0;
            int count; 
            int SIZE = 4;
            int[] score = new int[SIZE];
            double[] avg = new double[SIZE];
            int total = 0, number;


            for (count = 0; count < 4; count++)
            {
                Console.Write("Input a number between 1 - 100: ");
                number = Convert.ToInt32(Console.ReadLine());
                total += number;

                while (true)
                {
                    if (!(score[count] <= 1 && score[count] >= 100))
                    {
                        Console.WriteLine("Input is Invalid. Please enter a number between 1 - 100. ");
                        score[count] = Convert.ToInt32(Console.ReadLine());
                    }
                    else
                    {
                        break;

Aucun commentaire:

Enregistrer un commentaire