Postal Barcode Assignment

Hello! I would like assistance with the code below. My issue is that I do not know how to output the equivalent barcode for each digit of the zipcode. My code is only outputting the equivalent barcode for the first digit of 9. The zip code I am working with is 95014.
Would you be able to give me a hint as to what I need to add? I am a bit lost with user defined functions and just recently learned it in class but the lecture wasn't that great. Any help would be greatly appreciated, thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  #include <iostream>
using namespace std;

void getzipcode(int zip);
void printzipcode(int zip);




int main()
{
	int zipcode = int();

	getzipcode(zipcode);
	printzipcode(zipcode);


	return 0;
}

void getzipcode(int zip)
{
	int zipcode = int();
	int digit1 = int();
	int digit2 = int();
	int digit3 = int();
	int digit4 = int();
	int digit5 = int();
	int digitsum = int();
	int diff = int();
	int cordigit = int();

	cout << "Enter your zipcode: ";
	cin >> zipcode;

	digit1 = (zipcode % 100000) / 10000;
	cout << "Digit 1: " << digit1 << endl;
	digit2 = (zipcode % 10000) / 1000;
	cout << "Digit 2: " << digit2 << endl;
	digit3 = (zipcode % 1000) / 100;
	cout << "Digit 3: " << digit3 << endl;
	digit4 = (zipcode % 100) / 10;
	cout << "Digit 4: " << digit4 << endl;
	digit5 = zipcode % 10;
	cout << "Digit 5: " << digit5 << endl;

	digitsum = digit1 + digit2 + digit3 + digit4 + digit5;
	cout << "Sum of Digits: " << digitsum << endl;

	diff = digitsum % 10;
	//cout << "difference" << diff << endl;

	if (diff < 5)
	{
		cordigit = (5 - diff);
		cout << "Correction Digit: " << cordigit << endl;
	}

	if (diff == 5)
	{
		cordigit = (5 + diff);
		cout << "Correction Digit: " << cordigit << endl;
	}

	if (diff > 5)
	{
		cordigit = (10 - diff);
		cout << "Correction Digit: " << cordigit << endl;
	}
}


void printzipcode(int digit)
{
	cout << "Zipcode Barcode is |";

	if (digit == 1)
		cout << ":::||";
	else if (digit == 2)
		cout << "::|:|";
	else if (digit == 3)
		cout << "::||:";
	else if (digit == 4)
		cout << ":|::|";
	else if (digit == 5)
		cout << ":|:|:";
	else if (digit == 6)
		cout << ":||::";
	else if (digit == 7)
		cout << "|:::|";
	else if (digit == 8)
		cout << "|::|:";
	else if (digit == 9)
		cout << "|:|::";
	else if (digit == 0)
		cout << "||:::";

	cout << "|" << endl;

}
Last edited on
Line 14: You call getzipcode passing zipcode by value. The zipcode variable at line 12 is never updated. You need to pass zipcode by reference.

Line 15: When you call printzipcode(), zipcode is still 0.
Last edited on
Hi @abstractionanon Thank you for responding! However, I do not understand. Why did it read the first digit of 9 if the zipcode is still 0?
I believe that's the correction digit.
@AbstractionAnon thank you for pointing that out.
Topic archived. No new replies allowed.