postal bar-code lab issue

.....
Last edited on
It may make your life easier if you make a lookup array for each of your digits.
1
2
3
4
5
6
7
8
9
10
    std::string barCodes[] = { "||:::",   //0
                               ":::||",   //1
                               "::|:|",   //2
                               "::||:",   //3
                               ":|::|",   //4
                               ":|:|:",   //5
                               ":||::",   //6
                               "|:::|",   //7
                               "|::|:",   //8
                               "|:|::" }; //9 
Then, as long as you had an int representing a single-digit decimal number, you could say something like this:
1
2
    int theDigit = 3;
    std::cout << barCodes[theDigit] << std::endl; //will print ::||: 
This way, when you convert a single digit out of your zip code, you can just look it up from the barCodes array.

As for the overall algorithmic structure, assuming you have this lookup table barCodes, your flow should go something like this:
1. Get zip code from user.
2. For each digit, print barCodes[digit]
3. Find the CheckDigit
4. Print barCodes[CheckDigit]
Last edited on
Topic archived. No new replies allowed.