Integer Statistics



Integer Statistics

This program has a more advanced method concept. You enter 10 integers and it returns some statistics about those numbers.

Here's the code!

                            using System;
                            namespace integerStatistics
                            {
                                class IntegerStatistics
                                {
        
                                    static void Main(string[] args)
                                    {
                                        int counter = 0;
                                        int[] tenNums = new int[10];
                                        int sum = 0, avg = 0;
                                        firstMethod(tenNums, ref counter);
                                        reverse(tenNums);

                                        for (int x = 0; x < tenNums.Length; x++)
                                        {
                                            Console.WriteLine("Number {0} is {1} ", x + 1, tenNums[x]);
                                            sum += tenNums[x];
                                        }
                                        avg = sum / counter;
                                        Console.WriteLine("The highest value is {0}. The lowest value is {1}", tenNums[9], tenNums[0]);
                                        Console.WriteLine("The sum of all the values in the array is: {0}", sum);
                                        Console.WriteLine("The average of the sum is {0}", avg);
                                        Console.ReadLine();
                                    }

                                    public static void firstMethod(int[] tenInts, ref int counter)
                                    {
            
                                        Console.WriteLine("Enter (exit) to stop the program.");
                                        for (int x = 0; x < 10; ++x)
                                        {
                                            int num = 0;
                                            Console.Write("Please enter a number: ");
                                            string enteredString = Console.ReadLine();

                                            while(!int.TryParse(enteredString, out num))
                                            {
                                                Console.Write("You must enter a whole number. Try again: ");
                                                enteredString = Console.ReadLine();
                                            }
                                            if (num == 11)
                                            {
                                                break;
                                            }
                                            else
                                            {
                                                tenInts[x] = num;
                                                counter++;
                                            }
                                        }
                                    }

                                    public static void reverse(int[] tenInts)
                                    {
                                        Array.Sort(tenInts);
                                    }
                                }
                            }