Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Beginner array program, need help!!!

Beginner array program, need help!!!

Scheduled Pinned Locked Moved C#
data-structureshelplearning
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cmh623
    wrote on last edited by
    #1

    Here is what I have so far: using System; namespace ZipArray { class Program { public class ZipSort { string[] zipCodes = new string[10] { "33701", "33702", "33703", "33704", "33705", "33706", "33707", "33708", "33709", "33710"}; int x; Console.Write("Please enter a zip-code : "); string zipSearch = Console.ReadLine(); bool found = false; foreach(string zip in zipCodes) { if (zip == zipSearch) { found = true; break; } } Console.WriteLine(); if (found) { Console.WriteLine("The zip-code, {0}, is delivered to", zipSearch); } else { Console.WriteLine("The zip-code, {0}, is not delivered to", zipSearch); Console.WriteLine(); Console.WriteLine("The full list is :"); Console.WriteLine(); Array.Reverse(zipCodes); for(x=0; x Console.WriteLine(zipCodes[x]); } } I have been unable to make this program run correctly thus far, I am trying to make it to where it will allow the user to enter a zip code and if it is on the list it will read "the zip code "0" is delivered to" and after that to sort the zip codes in descending order. Any help would be much appreciated!

    C Y 2 Replies Last reply
    0
    • C cmh623

      Here is what I have so far: using System; namespace ZipArray { class Program { public class ZipSort { string[] zipCodes = new string[10] { "33701", "33702", "33703", "33704", "33705", "33706", "33707", "33708", "33709", "33710"}; int x; Console.Write("Please enter a zip-code : "); string zipSearch = Console.ReadLine(); bool found = false; foreach(string zip in zipCodes) { if (zip == zipSearch) { found = true; break; } } Console.WriteLine(); if (found) { Console.WriteLine("The zip-code, {0}, is delivered to", zipSearch); } else { Console.WriteLine("The zip-code, {0}, is not delivered to", zipSearch); Console.WriteLine(); Console.WriteLine("The full list is :"); Console.WriteLine(); Array.Reverse(zipCodes); for(x=0; x Console.WriteLine(zipCodes[x]); } } I have been unable to make this program run correctly thus far, I am trying to make it to where it will allow the user to enter a zip code and if it is on the list it will read "the zip code "0" is delivered to" and after that to sort the zip codes in descending order. Any help would be much appreciated!

      C Offline
      C Offline
      CKnig
      wrote on last edited by
      #2

      where is the Problem? In the input or show section (the input/find looks fine but the for-loop won't compile (it's not even closed))?

      1 Reply Last reply
      0
      • C cmh623

        Here is what I have so far: using System; namespace ZipArray { class Program { public class ZipSort { string[] zipCodes = new string[10] { "33701", "33702", "33703", "33704", "33705", "33706", "33707", "33708", "33709", "33710"}; int x; Console.Write("Please enter a zip-code : "); string zipSearch = Console.ReadLine(); bool found = false; foreach(string zip in zipCodes) { if (zip == zipSearch) { found = true; break; } } Console.WriteLine(); if (found) { Console.WriteLine("The zip-code, {0}, is delivered to", zipSearch); } else { Console.WriteLine("The zip-code, {0}, is not delivered to", zipSearch); Console.WriteLine(); Console.WriteLine("The full list is :"); Console.WriteLine(); Array.Reverse(zipCodes); for(x=0; x Console.WriteLine(zipCodes[x]); } } I have been unable to make this program run correctly thus far, I am trying to make it to where it will allow the user to enter a zip code and if it is on the list it will read "the zip code "0" is delivered to" and after that to sort the zip codes in descending order. Any help would be much appreciated!

        Y Offline
        Y Offline
        Yitzchok Dev
        wrote on last edited by
        #3

        using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] zipCodes = new string[10]{"33701","33702","33703","33704","33705", "33706","33707","33708","33709","33710"}; Console.Write("Please enter a zip-code : "); string zipSearch = Console.ReadLine(); bool found = false; foreach (string zip in zipCodes) { if (zip == zipSearch) { found = true; break; } } Console.WriteLine(); if (found) { Console.WriteLine("The zip-code, {0}, is delivered to", zipSearch); } else { Console.WriteLine("The zip-code, {0}, is not delivered to", zipSearch); Console.WriteLine(); Console.WriteLine("The full list is :"); Console.WriteLine(); } Array.Reverse(zipCodes); for (int i = 0; i < zipCodes.Length; i++) { Console.WriteLine(zipCodes[i]); } Console.WriteLine("Press a key to Continue."); Console.ReadLine(); } } }

        C 1 Reply Last reply
        0
        • Y Yitzchok Dev

          using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] zipCodes = new string[10]{"33701","33702","33703","33704","33705", "33706","33707","33708","33709","33710"}; Console.Write("Please enter a zip-code : "); string zipSearch = Console.ReadLine(); bool found = false; foreach (string zip in zipCodes) { if (zip == zipSearch) { found = true; break; } } Console.WriteLine(); if (found) { Console.WriteLine("The zip-code, {0}, is delivered to", zipSearch); } else { Console.WriteLine("The zip-code, {0}, is not delivered to", zipSearch); Console.WriteLine(); Console.WriteLine("The full list is :"); Console.WriteLine(); } Array.Reverse(zipCodes); for (int i = 0; i < zipCodes.Length; i++) { Console.WriteLine(zipCodes[i]); } Console.WriteLine("Press a key to Continue."); Console.ReadLine(); } } }

          C Offline
          C Offline
          cmh623
          wrote on last edited by
          #4

          Thanks alot F16I ! I think I see what I was doing wrong now. Much obliged !

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups