Outputting a 2 digit number with a space in between using an array

Ok. Im working on an assignment were you're supposed to output a number using arrays. I have the code working but my number is mashed together in 1 digit. I'm supposed to have them read side by side like a normal number (24) and it cannot be read up and down. If anyone can guide me to the solution, it would be much appreciated.
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
101
102
103
104
105
106
  int main ()
{
	
	int score = 24;

   int numArr[10][7][5] = {
       {
           {0, 1, 1, 1, 0},
           {1, 0, 0, 0, 1},
           {1, 0, 0, 1, 1}, 
           {1, 0, 1, 0, 1}, 
           {1, 1, 0, 0, 1}, 
           {1, 0, 0, 0, 1},
           {0, 1, 1, 1, 0} 
         },{
            {0, 0, 1, 0, 0},
            {0, 1, 1, 0, 0},
            {0, 0, 1, 0, 0}, 
            {0, 0, 1, 0, 0}, 
            {0, 0, 1, 0, 0}, 
            {0, 0, 1, 0, 0},
            {0, 1, 1, 1, 0} 
         },{
            {0, 1, 1, 1, 0},
            {1, 0, 0, 0, 1},
            {0, 0, 0, 0, 1}, 
            {0, 0, 0, 1, 0}, 
            {0, 0, 1, 0, 0}, 
            {0, 1, 0, 0, 0},
            {1, 1, 1, 1, 1} 
         },{
            {0, 1, 1, 1, 0},
            {1, 0, 0, 0, 1},
            {0, 0, 0, 0, 1}, 
            {0, 1, 1, 1, 1}, 
            {0, 0, 0, 0, 1}, 
            {1, 0, 0, 0, 1},
            {0, 1, 1, 1, 0} 
         },{
            {0, 0, 0, 1, 0},
            {0, 0, 1, 1, 0},
            {0, 1, 0, 1, 0}, 
            {1, 0, 0, 1, 0}, 
            {1, 1, 1, 1, 1}, 
            {0, 0, 0, 1, 0},
            {0, 0, 0, 1, 0}
         },{
            {1, 1, 1, 1, 1},
            {1, 0, 0, 0, 0},
            {1, 0, 0, 0, 0}, 
            {1, 1, 1, 1, 0}, 
            {0, 0, 0, 0, 1}, 
            {1, 0, 0, 0, 1},
            {0, 1, 1, 1, 0} 
         },{
            {0, 1, 1, 1, 0},
            {1, 0, 0, 0, 1},
            {1, 0, 0, 0, 0}, 
            {1, 1, 1, 1, 0}, 
            {1, 0, 0, 0, 1}, 
            {1, 0, 0, 0, 1},
            {0, 1, 1, 1, 0}
         },{
            {1, 1, 1, 1, 1},
            {0, 0, 0, 0, 1},
            {0, 0, 0, 1, 0}, 
            {0, 0, 1, 0, 0}, 
            {0, 0, 1, 0, 0}, 
            {0, 0, 1, 0, 0},
            {0, 0, 1, 0, 0} 
         },{
            {0, 1, 1, 1, 0},
            {1, 0, 0, 0, 1},
            {1, 0, 0, 0, 1}, 
            {0, 1, 1, 1, 0}, 
            {1, 0, 0, 0, 1}, 
            {1, 0, 0, 0, 1},
            {0, 1, 1, 1, 0}
         },{
            {0, 1, 1, 1, 0},
            {1, 0, 0, 0, 1},
            {1, 0, 0, 0, 1}, 
            {0, 1, 1, 1, 1}, 
            {0, 0, 0, 0, 1}, 
            {1, 0, 0, 0, 1},
            {0, 1, 1, 1, 0} }};
				
   int dig1 = score / 10;
   int dig2 = score % 10;
		
	for (int i = 0; i < 7; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			numArr[0][i][j] = numArr[dig1][i][j] + numArr[dig2][i][j];
				
				if (numArr[0][i][j] == 0)
					cout << " ";
				else
					cout << "#";
			}
			cout << "\n";
		}
	
	return 0;
}
Last edited on
No one? *Sigh*.
your question is not clear.
I have the code working but my number is mashed together in 1 digit.

Is your problem just to print the digits of the number with a space between them?

I'm supposed to have them read side by side like a normal number (24) and it cannot be read up and down

what does reading a number up and down mean?
Yes, my problem is printing the 2 digits with a space in between them.

I mean having the 4 on the right side of the 2 like a normal 2 digit number, instead of the 4 under the 2 read vertically. I want the number read horizontally. Here is an example.

[IMG]http://i60.tinypic.com/28srllz.png[/IMG]
Last edited on
closed account (48T7M4Gy)

You need to print the numbers by scan-lines. I changed the names of variables to make it clearer. I suggest you use a char array instead of if to print a space or an asterisk. :)
Last edited on
Wow that really helped! I just changed the code up a bit to make it look like how i want. You are a life saver!!
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

	char character[] = { ' ', '*' };

        int score = 24;
	int tens = score / 10;
	int units = score % 10;

	for (int row = 0; row < 7; row++)
	{
		for (int column = 0; column < 5; column++)
		{
			std::cout << character[number[tens][row][column]];
		}

		std::cout << " ";

		for (int column = 0; column < 5; column++)
		{
			std::cout << character[number[units][row][column]];
		}

		std::cout << std::endl;
	}


This does the trick.
Last edited on
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
int main ()
{
	
	int score = 24;

   int numArr[10][7][5] = {
       {
           {0, 1, 1, 1, 0},
           {1, 0, 0, 0, 1},
           {1, 0, 0, 1, 1}, 
           {1, 0, 1, 0, 1}, 
           {1, 1, 0, 0, 1}, 
           {1, 0, 0, 0, 1},
           {0, 1, 1, 1, 0} 
         },{
            {0, 0, 1, 0, 0},
            {0, 1, 1, 0, 0},
            {0, 0, 1, 0, 0}, 
            {0, 0, 1, 0, 0}, 
            {0, 0, 1, 0, 0}, 
            {0, 0, 1, 0, 0},
            {0, 1, 1, 1, 0} 
         },{
            {0, 1, 1, 1, 0},
            {1, 0, 0, 0, 1},
            {0, 0, 0, 0, 1}, 
            {0, 0, 0, 1, 0}, 
            {0, 0, 1, 0, 0}, 
            {0, 1, 0, 0, 0},
            {1, 1, 1, 1, 1} 
         },{
            {0, 1, 1, 1, 0},
            {1, 0, 0, 0, 1},
            {0, 0, 0, 0, 1}, 
            {0, 1, 1, 1, 1}, 
            {0, 0, 0, 0, 1}, 
            {1, 0, 0, 0, 1},
            {0, 1, 1, 1, 0} 
         },{
            {0, 0, 0, 1, 0},
            {0, 0, 1, 1, 0},
            {0, 1, 0, 1, 0}, 
            {1, 0, 0, 1, 0}, 
            {1, 1, 1, 1, 1}, 
            {0, 0, 0, 1, 0},
            {0, 0, 0, 1, 0}
         },{
            {1, 1, 1, 1, 1},
            {1, 0, 0, 0, 0},
            {1, 0, 0, 0, 0}, 
            {1, 1, 1, 1, 0}, 
            {0, 0, 0, 0, 1}, 
            {1, 0, 0, 0, 1},
            {0, 1, 1, 1, 0} 
         },{
            {0, 1, 1, 1, 0},
            {1, 0, 0, 0, 1},
            {1, 0, 0, 0, 0}, 
            {1, 1, 1, 1, 0}, 
            {1, 0, 0, 0, 1}, 
            {1, 0, 0, 0, 1},
            {0, 1, 1, 1, 0}
         },{
            {1, 1, 1, 1, 1},
            {0, 0, 0, 0, 1},
            {0, 0, 0, 1, 0}, 
            {0, 0, 1, 0, 0}, 
            {0, 0, 1, 0, 0}, 
            {0, 0, 1, 0, 0},
            {0, 0, 1, 0, 0} 
         },{
            {0, 1, 1, 1, 0},
            {1, 0, 0, 0, 1},
            {1, 0, 0, 0, 1}, 
            {0, 1, 1, 1, 0}, 
            {1, 0, 0, 0, 1}, 
            {1, 0, 0, 0, 1},
            {0, 1, 1, 1, 0}
         },{
            {0, 1, 1, 1, 0},
            {1, 0, 0, 0, 1},
            {1, 0, 0, 0, 1}, 
            {0, 1, 1, 1, 1}, 
            {0, 0, 0, 0, 1}, 
            {1, 0, 0, 0, 1},
            {0, 1, 1, 1, 0} }};
				
   int dig1 = score / 10;
	int dig2 = score % 10;

	for (int i = 0; i < 7; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			if (numArr[dig1][i][j] == 0)
			cout << " ";
			else
				cout << "#";
		}

		cout << " ";

		for (int j = 0; j < 5; j++)
		{
			if (numArr[dig2][i][j] == 0)
				cout << " ";
			else
				cout << "#";
		}

		cout << endl;
	}
	cout << "             " << endl;
	
	return 0;
}


This is what I did.
closed account (48T7M4Gy)
Excellent! Cheers :)
Topic archived. No new replies allowed.