Thread: Please Help!!! Validation loop for postcode!!

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    4

    Please Help!!! Validation loop for postcode!!

    I was wondering if you could help me as I am new to c++

    I need to validate a postcode using the following functions


    1. Write a function called isValidPostcode:

    Prototype: bool isValidPostcode(char postcode[])
    Parameter: character string (postcode).
    Return value: returns true if the postcode is valid, false otherwise.
    Functionality: works out whether the given postcode is valid or invalid.

    I don't know where to begin! please help me asap and I will be forever grateful

    thanks

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The first place to begin is to lay out the rules, in english, of what a valid postcode is. For example, in the US, a 5 digit number is a valid postcode, as is the 5-4 format. Once you have the rules, you can implement the checking for those rules in code.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    4
    Okey I have set out the rules. Its a british postcode so it goes AAN NAA. Any more tips on where to go now? Any help at all is welcome. Thanks

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Does A stand for any alphabetic character? Does N stand for any numeric character?

    How would you validate the postcode in real life? Write out the steps. For example, here is how I would validate an American zip code that takes the format NNNNN-NNNN:

    1. Check the length of the string, it must be 10 characters. If not - invalid.
    2. For each character in the string:
    2a. If it is the 6th character in the string (index #5), it must be the '-' character. If not - invalid.
    2b. Otherwise if it is not the 6th character, it must be a numeric character. If not - invalid.
    3. If the first 2 checks succeed, the zip code is valid.

    If you can do that for your post code, it is real close to actual code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  2. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  4. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 07:19 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM