zipcode and checksum to barcode issue

Hey again, so I'm having trouble with this conversion of a zipcode to a barcode. I feel like this shouldn't be so hard but I've done so much reading and research about it that I think my head is gonna explode so any help would be appreciated. As you can see, I'm kinda lost at the bottom of the program. It's returning the zipcode as "invalid". There are no compiling errors.
Here's what I got, and I swear I think I'm on the right track but I could also just be stupid haha
(Hint I'm pretty new to C++ so)


//The following converts the user input zipcode into a barcode.
string result;
char digit;
{
if (digit == '0')
result= "||:::";
else if (digit == '1')
result= ":::||";
else if (digit == '2')
result= "::|:|";
else if (digit == '3')
result= "::||:";
else if (digit == '4')
result= ":|::|";
else if (digit == '5')
result= ":|:|:";
else if (digit == '6')
result= ":||::";
else if (digit == '7')
result= "|:::|";
else if (digit == '8')
result= "|:::|";
else if (digit == '9')
result= "|:|::";
else
result= "Invalid";

}
string zipcode, checkSum, pseudocode, final_Barcode;
int checkSum=zipcode%10

pseudocode=zipcode+checkSum; //So as to add the 6th digit to the barcode as a checksum.

final_Barcode=result+pseudocode;
cout<<"| "<<final_Barcode<<" |"<<endl;
return 0;
}
Hello cmangum3,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

Not sure what you are expecting with this bit of code? There is not enough there to even compile and it looks like there are several functions missing most importantly "main".

It looks like it will be awhile before I can make anything out of this.

I think you should start with
http://www.cplusplus.com/doc/tutorial/program_structure/ Do not bother reading the last section about "using namespace std". You should avoid using this.
http://www.cplusplus.com/doc/tutorial/functions/

Thee line pseudocode=zipcode+checkSum; you are trying to add an "int" to a "string". This will not work. First you would have to change "checkSum" to a string before you can add it to "zipcode".

I will see what I can do with what you have.

Hope that helps,

Andy
Last edited on
Topic archived. No new replies allowed.