Wednesday, October 26, 2011

Midterm code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExamExample
{
    class Program
    {
        const int SIZE = 50;
        static void Main(string[] args)
        {
            Program p = new Program();
            p.CreateArrays();
            p.PauseIt();
        }

       

        private void CreateArrays()
        { 
            int[] numbers= new int[SIZE];
            FillArray(numbers);

        }

        private void FillArray(int[] numbers)
        {
            Random rand = new Random();
            for (int i = 0; i < SIZE; i++)
            {
                numbers[i] = rand.Next(1, 100);
            }
            GetEvenNumbers(numbers);
        }

        private void GetEvenNumbers(int[] numbers)
        {
            int evenCount = 0;
            int oddCount = 0;

            for (int i = 0; i < SIZE; i++)
            {
                if (numbers[i] % 2 == 0)
                {
                    evenCount++;
                }
                else
                {
                    oddCount++;
                }

            }
            Console.WriteLine("There were {0} even numbers and {1} odd numbers", evenCount, oddCount);
           
        }

        private void PauseIt()
        {
            Console.WriteLine("\n\nPress any key to exit");
            Console.ReadKey();
        }

       
    }
}


No comments:

Post a Comment