1 // Student: Pat Moss www.patmoss.com/cis162ad/ 2 // Instructor: Dave Hammer http://members.cox.net/dwhammer/ 3 4 // CIS162AD -- C Sharp (C#) -- Section 5832 5 // Professor: Dave Hammer dwhammer@cox.net 6 // http://members.cox.net/dwhammer/ 7 // Student: Pat Moss patmoss@patmoss.com 8 // http://www.patmoss.com/cis162ad/ 9 10 // Midterm 11 // III. Programming Exercise 12 // Write a program for a package delivery service. The program 13 // contains an array that holds the 10 ZIP codes to which the 14 // company delivers packages. Prompt a user to enter a ZIP code 15 // and display a message indicating whether the ZIP code is one 16 // to which the company delivers. Turn in your source code for 17 // this program. 18 19 // Program Name: Zipcodes.cs Rev. 01 02-28-2006 by pat moss 20 // Textbook: Visual C# .NET Programming, Barbara Doyle, 0619159979 21 22 using System; 23 namespace zipcodes 24 { 25 public class zipcodes 26 { 27 public static void Main() 28 { 29 bool moreToDo = true; 30 int inpZipcode = 0; 31 bool zipcodeOK = false; 32 33 DisplayInstructions(); 34 35 while (moreToDo == true) 36 { 37 Console.Write("\nEnter a ZIP code value (5 digits): "); 38 inpZipcode = Convert.ToInt32(Console.ReadLine()); 39 40 if (inpZipcode > 0) 41 { 42 zipcodeOK = checkZipcode(inpZipcode); 43 44 switch (zipcodeOK) 45 { 46 case true: 47 Console.WriteLine("The ZIP code {0} is valid.", inpZipcode); 48 break; 49 case false: 50 Console.WriteLine("The ZIP code {0} is not valid.", inpZipcode); 51 break; 52 default: 53 break; 54 } 55 } 56 else 57 { 58 Console.WriteLine("\nZipcode application -- All done..."); 59 moreToDo = false; 60 } 61 } 62 } 63 64 // display user instructions 65 static void DisplayInstructions() 66 { 67 Console.WriteLine("Zipcode application by Student: Pat Moss Instructor: Dave Hammer\n"); 68 Console.WriteLine("CIS162AD C# Midterm, III. Programming Exercise\n"); 69 Console.WriteLine("Zipcodes.cs Rev. 01 Feb. 28, 2006\n"); 70 Console.WriteLine("User Instructions:"); 71 Console.WriteLine("Enter various 5-digit US ZIP codes, one at a time, and press Enter."); 72 Console.WriteLine("Then the program will display whether the ZIP code is valid."); 73 Console.WriteLine("Enter a zero or negative ZIP code value to quit."); 74 } 75 76 // check to determine if the input zip code is valid 77 static bool checkZipcode(int inpZip) 78 { 79 int[] ziptbl = {85001, 85002, 85003, 85004, 85005, 80 85006, 85007, 85008, 85009, 85010}; 81 int i = 0; 82 for (i=0; i<10; i++) 83 { 84 if(ziptbl[i] == inpZip) 85 return true; 86 } 87 return false; 88 } 89 } 90 } 91