program not working properly

I have this code where I have the user input their zip code and I convert it to a bar code. It all works fine until I want it to output the bar code properly.
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
#include <iostream> 
#include <iomanip>
#include <string> 
#include <conio.h> 
using namespace std; 

int main()
{ 
	int total = 0; 
	char ch[5];
	int check; 

	cout << "Please input your 5 digit zip code: "; 
	
	
	for (int i=0; i<5; i++)
{
	ch[i] = getch();
	cout << ch[i];
	total = total + (ch[i] - '0'); 

}

	cout << endl;
	check = total % 10;
	if (check <= 5 ) 
	{ 
		cout << "Check Digit:" << check << endl;
	} 
	else if ( check > 5) 
	{ 
		cout << "Check Digit:" << 10 - check << endl; 
	}

	for (int i=0; i<5; i++)
{
	if (ch[i] = 9) 
	{
		cout << "|:|::";
	}
	else if (ch[i] = 8)
	{
		cout << "|::|:";
	}
	else if (ch[i] = 7)
	{
		cout << "|:::|";
	}
	else if (ch[i] = 6)
	{
		cout << ":||::";
	}
	else if (ch[i] = 5)
	{
		cout << ":|:|:";
	}
	else if (ch[i] = 4)
	{
		cout << ":|::|";
	}
	else if (ch[i] = 3) 
	{
		cout << "::||:";
	}
	else if (ch[i] = 2)
	{
		cout << "::|:|";
	}
	else if (ch[i] = 1)
	{
		cout << ":::||";
	}
	else if (ch[i] = 0)
	{
		cout << "||:::";
	}


}



	
	
return 0;
}


also I did have some help from someone and they told me to do ch[i] - '0' but I didn't know the purpose of that. Can someone explain that to me please?
ch[i] - '0' is a cheap hack for "converting" char's of digits into numbers.

For example, '2' will be converted to 2, and '9' will be converted to 9 and so on. They must be converted because, for example, '2' is a character with an ASCII code of 50 (0x32 hexadecimal) which is obviously not the same as 2.

http://www.cplusplus.com/doc/ascii/

It all works fine until I want it to output the bar code properly.

Your code doesn't work because you don't do comparisons.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	if (ch[i] = 9) // single =, assignment, ch[i] gets the value 9
	{
		cout << "|:|::";
	}
	else if (ch[i] = 8) // single =, assignment, ch[i] gets the value 8
	{
		cout << "|::|:";
	}

// what you intended...

	if (ch[i] == 9) // double =, comparison, ch[i] tested against 9
	{
		cout << "|:|::";
	}
	else if (ch[i] == 8) // double =, comparison, ch[i] tested against 8
	{
		cout << "|::|:";
	}

Topic archived. No new replies allowed.