I am testing a program that I am trying to run and having some difficulties with it. If you run this program I am able to compille it fine but will not return anything and stalls on me...Here are the instructions.....

There are 25 digits split into five groups of five digits each...

10100 10100 01010 11000 01001

Next, consider each group fo five digits. Each digit stands for a number. From left to right the digits encode the values 7,4,2,1,0. Multilply the value with the digit and compute the sum to get the final encoded digit for the zip code....

Here is an example table
bar code digit 1 0 1 0 0
value 7 7 2 1 0
digit * value 7 0 2 0 0

so the first zip code digit will be 7 + 0 +2 + 0 + 0 = 9

REpeat this foe each group of five digits and concatenate to get the complete zip code. There is one special value. If the sume of a group of five digits is 11, then represent this with a 0.

Write z zip code class that encodes and decodes five-digit bar codes. The class should have two constructors. The first constructor should input the zip code as an integer, and the second constructor should input the zip code as a bar code stirng consisting of 0's and 1's. The class should have at least 2 public member functions, one to return the zip code as an integer, and the other to return the zip code as a string. All helper functions should be declared private. Embed your class definition in a suitable test program. Your program should print an error message if an invalid test is passed to the constructor...

here is my code I have so far...the only help I really need is on why I cannot see and return values but if you see any additional issues I will be having from these instructions please let me know...

``````#include <iostream>
#include <string>

using namespace std;

class POSTNET
{
public:
void valueOfDigits(int valueDigit1, int valueDigit2, int valueDigit3, int valueDigit4, int valueDigit5);
int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5);
int addDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5);
};

void valueOfDigits(int valueDigit1, int valueDigit2, int valueDigit3, int valueDigit4, int valueDigit5)
{
valueDigit1 = 7;
valueDigit2 = 4;
valueDigit3 = 2;
valueDigit4 = 1;
valueDigit5 = 0;
}

int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5)
{
int digit1 = 0, digit2 = 0, digit3 = 0, digit4 = 0, digit5 = 0, valueDigit1 = 0, valueDigit2 = 0, valueDigit3 = 0, valueDigit4 = 0, valueDigit5 = 0;
productOfDigit1 = digit1 * valueDigit1;
productOfDigit2 = digit2 * valueDigit2;
productOfDigit3 = digit3 * valueDigit3;
productOfDigit4 = digit4 * valueDigit4;
productOfDigit5 = digit5 * valueDigit5;
return 0;
}

int main()
{
int digit1, digit2, digit3, digit4, digit5, productOfDigit1 = 0, productOfDigit2 = 0, productOfDigit3 = 0, productOfDigit4 = 0, productOfDigit5 = 0;
cout << "Enter the first five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
cout << "Enter the second five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
cout << "Enter the third five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
cout << "Enter the fourth five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
cout << "Enter the last five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
valueOfDigits(digit1, digit2, digit3, digit4, digit5);
multiplyDigits(productOfDigit1, productOfDigit2, productOfDigit3, productOfDigit4, productOfDigit5);
cout << "The zip code is: " << endl;
cin >> productOfDigit1 >> productOfDigit2 >> productOfDigit3 >> productOfDigit4 >> productOfDigit5;
return 0;
}``````

Look carefully at this block of code. You overwrite values without doing anything with them.

``````cout << "Enter the first five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
cout << "Enter the second five bar code digits …``````

What compiler are you using? Tag a system("pause"); before return 0; and see what happens. Also

``````int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5)
{
int digit1 = 0, digit2 = 0, digit3 = 0, digit4 = 0, digit5 = 0, valueDigit1 = 0, …``````

## All 5 Replies

Look carefully at this block of code. You overwrite values without doing anything with them.

``````cout << "Enter the first five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
cout << "Enter the second five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
cout << "Enter the third five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
cout << "Enter the fourth five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
cout << "Enter the last five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;``````

What compiler are you using? Tag a system("pause"); before return 0; and see what happens. Also

``````int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5)
{
int digit1 = 0, digit2 = 0, digit3 = 0, digit4 = 0, digit5 = 0, valueDigit1 = 0, valueDigit2 = 0, valueDigit3 = 0, valueDigit4 = 0, valueDigit5 = 0;
productOfDigit1 = digit1 * valueDigit1;
productOfDigit2 = digit2 * valueDigit2;
productOfDigit3 = digit3 * valueDigit3;
productOfDigit4 = digit4 * valueDigit4;
productOfDigit5 = digit5 * valueDigit5;
return 0;
}``````

seems a bit confusing, why do you declare everything as 0 if you already declared valueDigit and taken the input of digit? The way I read this is

``````int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5)
{
int digit1 = 0, digit2 = 0, digit3 = 0, digit4 = 0, digit5 = 0, valueDigit1 = 0, valueDigit2 = 0, valueDigit3 = 0, valueDigit4 = 0, valueDigit5 = 0;
0 = 0* 0;
0= 0* 0;
0= 0* 0;
0= 0* 0;
0= 0* 0;
return 0;
}``````

Made a few changes and still not returning and values.....

``````#include <iostream>
#include <string>

using namespace std;

class ZipCodes
{
public:
void valueOfDigits(int valueDigit1, int valueDigit2, int valueDigit3, int valueDigit4, int valueDigit5);
int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5);

};

//Values of each group of five digits from left to right
void valueOfDigits(int valueDigit1, int valueDigit2, int valueDigit3, int valueDigit4, int valueDigit5)
{
valueDigit1 = 7;
valueDigit2 = 4;
valueDigit3 = 2;
valueDigit4 = 1;
valueDigit5 = 0;
}

//Multiply the bar code digits and values to get a product of the digits
int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5)
{
int digit1, digit2, digit3, digit4, digit5, valueDigit1, valueDigit2, valueDigit3, valueDigit4, valueDigit5, zipDigit;
productOfDigit1 = digit1 * valueDigit1;
productOfDigit2 = digit2 * valueDigit2;
productOfDigit3 = digit3 * valueDigit3;
productOfDigit4 = digit4 * valueDigit4;
productOfDigit5 = digit5 * valueDigit5;
zipDigit = productOfDigit1 + productOfDigit2 + productOfDigit3 + productOfDigit4 + productOfDigit1;
return zipDigit;
}

int main()
{
int digit1, digit2, digit3, digit4, digit5, productOfDigit1, productOfDigit2, productOfDigit3, productOfDigit4, productOfDigit5;
cout << "Enter the first five bar code digits " << endl;
cin >> digit1 >> digit2 >> digit3 >> digit4 >> digit5;
valueOfDigits(digit1, digit2, digit3, digit4, digit5);
multiplyDigits(productOfDigit1, productOfDigit2, productOfDigit3, productOfDigit4, productOfDigit5);
cout << "The zip code is: " << endl;
cin >> productOfDigit1 >> productOfDigit2 >> productOfDigit3 >> productOfDigit4 >> productOfDigit5;
return 0;
}``````

This function does nothing:

``````//Values of each group of five digits from left to right
void valueOfDigits(int valueDigit1, int valueDigit2, int valueDigit3, int valueDigit4, int valueDigit5)
{
valueDigit1 = 7;
valueDigit2 = 4;
valueDigit3 = 2;
valueDigit4 = 1;
valueDigit5 = 0;
}``````

This function may do something by returning something useful:

``int multiplyDigits(int productOfDigit1, int productOfDigit2, int productOfDigit3, int productOfDigit4, int productOfDigit5);``

but you never harness its return value, so it is lost:

``multiplyDigits(productOfDigit1, productOfDigit2, productOfDigit3, productOfDigit4, productOfDigit5);``

No information is outputted here:

``````cout << "The zip code is: " << endl;
cin >> productOfDigit1 >> productOfDigit2 >> productOfDigit3 >> productOfDigit4 >> productOfDigit5;``````

Tag a system("pause"); before return 0; and see what happens.

You might want to read this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.