All pastes #567087 Raw Edit

Mine

public text v1 · immutable
·published 2007-06-14 19:26 UTC
rendered paste body
/* Written by Jeremy Glassford
 * June 11th, 2007
 * Last Modified: June 14th, 2007
 * 
 * The program contains an array that holds 10 ZIP codes to which a company delivers. 
 * Prompt the user of the program to input a ZIP code and then display a message on screen 
 * that indicates whether the ZIP code is one to which the company delivers or not. 
 * Finally display all ZIP codes in the array in descending order.
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace JeremyGlassford_Lab7
{
    class Program
    {
        static void Main()
        {
            // The next three liens dispaly the name of the program.
            // And provide a space for charismatic purposes.
            System.Console.WriteLine("Jeremy Glassford");
            System.Console.WriteLine("Lab 7");
            System.Console.WriteLine();

            // Create a file object named "ZIPCodeFile".
            StreamReader ZIPCodeFile = new StreamReader("ZIPCode.txt");
            
            // This gets the size to declare the array from the first line of the file.
            int iArraySize = System.Convert.ToInt32(ZIPCodeFile.ReadLine());

            // This declares the array the program will use;
            // "ZIPCode" array to the size given by the first line of the file.
            string[] ZIPCode = new string[iArraySize];
    
            // This reads each line of the file into the array elements.
            // From the beginning the array to the end of the array.
            // Zero being the first element, and if the array has 10 elements 9 is it's last element.
            // 9 - 1 = 10.
            // So from zero to one less then the size given for the array.
            for (int i = 0; i < iArraySize; i++)
                // Place the line into the array.
                // FileObject.ReadLine() moves to the next line after each read.
                // So it reads and then moves to the next line 'automatically' for the programmer(s).
                ZIPCode[i] = ZIPCodeFile.ReadLine();

            // Prompt the user to input a zip code.
            System.Console.Write("Please Input ZIP Code : ");
            
            // Get the user's input and place it into a string.
            string sUserInput = System.Console.ReadLine();

            // Declare a tempary integer variable named 'a' and set it to 0.
            int a = 0;
            // Declare a boolean variable bMatch and set it to false.
            bool bMatchFound = false;
            // while 'a' is less then the length of the array named ZIPCode,
            // AND bMatch is false (hasn't found a match);
            while(a < ZIPCode.Length && bMatchFound == false)
            {
                // If the element numbered 'a' is the same as the user's input;
                if (ZIPCode[a] == sUserInput)
                    // Set bMatch to true.  This way we know a match was found.
                    bMatchFound = true;
                //Increment 'a' by one.
                a++;
            }
            // If a match is found, tell the user the company delivers there.
            if (bMatchFound)
                System.Console.WriteLine("Yes, we deliver here!");
            // If no match is found inform the user that the company does not deliver there.
            else
                System.Console.WriteLine("I'm sorry, we do not deliver to this area.");
            
            // Pause so the user can read the program's output.
            System.Console.ReadLine();
            
            
            // This wasn't necessary for the assignment,
            // but I feel this is should be here.
            System.Console.WriteLine("These are the ZIP codes we deliver to: ");
            System.Console.WriteLine();

            // I could have made this program modular.
            // This sorts ZIPCode.
            ZIPCode.Sort();
            // This reverses ZIPCode (so it will be displayed in descending order.)
            ZIPCode.Reverse();
            
            // From the start of the array (zero) to the end (Length);
            for (int p = 0; p < ZIPCode.Length; p++)
                // Write out each of the numbers (ZIP Codes) in IZIPCode.
                System.Console.WriteLine(ZIPCode[p]);

            // Pause so the user(s) can see the end result.
            System.Console.ReadLine();
           
        }
    }
}