All pastes #567044 Raw Edit

Stuff

public text v1 · immutable
·published 2007-06-14 19:02 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()
        {
            System.Console.WriteLine("Jeremy Glassford");
            System.Console.WriteLine("Lab 7");
            System.Console.WriteLine();

            StreamReader ZIPCodeFile = new StreamReader("ZIPCode.txt");
            
            string sArraySize = ZIPCodeFile.ReadLine();
            int iArraySize = System.Convert.ToInt32(sArraySize);

            string[] ZIPCode = new string[iArraySize];
    
            string Line;
            for (int i = 0; i < iArraySize; i++)
                ZIPCode[i] = ZIPCodeFile.ReadLine();

            //string[] ZIPCode = {"66301", "46302", "46303", "46304", "56305", "46306", "76307", "46308", "46309", "46310"};
            bool bMatchFound = false;
            string sUserInput;  // String of User's input.

            // 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.
            sUserInput = System.Console.ReadLine();

            int a = 0;
            while(a < ZIPCode.Length && bMatchFound == false)
            {
                if (ZIPCode[a] == sUserInput)
                    bMatchFound = true;
                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.
            System.Array.Sort(ZIPCode);
            // This reverses ZIPCode (so it will be displayed in descending order.)
            System.Array.Reverse(ZIPCode);
            
            // From the start of the array (zero) to the end (Length);
            for (int a = 0; a < ZIPCode.Length; a++)
                // Write out each of the numbers (ZIP Codes) in IZIPCode.
                System.Console.WriteLine(ZIPCode[a]);

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