lundi 23 octobre 2017

C# program as a console application that allows a user to input any no of positive integers between 1 and 100

Hi I'm fairly new to C# & I am trying to complete the following questions. Any help at all would be much appreciated. I'm trying to create a "do while" loop& if statements in order to run the program.

Write a C# program as a console application that allows a user to input any no of positive integers between 1 and 100. When the user enters any number outside the given range, the program displays the following: a) No of even numbers entered. b) Sum of even numbers entered. c) Average of even numbers entered (Average must be a real number formatted to display 2 decimal places). d) Highest and lowest even numbers

//Declare variables
        int inputValue;
        int odd = 0;
        int sum = 0;
        int evenCount = 0;
        int high = 0;
        int low = 0;
        double average;

        do
            {

            for (int number = 0; evenCount < 5; number++)
            {
                if (number % 2 == 0)//check if even
                {
                    sum = sum + number; //add to sum
                    evenCount++;//increment evenCount
                }
                number++;//increment number
                         //Display sum
                Console.WriteLine($"Sum of first five even numbers is: {sum}");
            }
        }
    }
}

}

Aucun commentaire:

Enregistrer un commentaire