text based graphics wont work

this keeps outputting random characters

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 #include<iostream>

using namespace std;

int main()
{
int map [6] [6] = {1};
int countx = 5;
int county = 5;

while(county > 0)
{
while(countx > 0)
{
	cout << map [countx] [county];
	countx --;
}
county --;
countx = 5;
cout << endl;
}
system("pause");
}
Last edited on
You set countx to 10, where your map is only of size 6...
...not mentioning that map isn't initialized.
now it's just blank
You have to set your map... C++ doesn't know what you want.
what do you mean by that???
char map [6] [6] = {'48'};
What is it supposed to mean?
You output nothing("it's just blank"), because there's nothing in map.
You should populate map, like this:
1
2
3
4
map[0][0] = 'x';
map[0][1] = 'y';
///...
map[5][5] = 'z';

Otherwise you have an empty array.
I was trying to fill the array with one thing
A side note that no one else mentioned is that single quotes are for a single character and 48 is two characters so that won't do what you are expecting it to do.
I know I was trying to get it to make the character that ascii code makes
In that case, you want to do things more like this:

1
2
int map[6][6]={48};
cout<<(char)map[0][0];

This would fill the whole array with 48's in each field, which would be 0 when printed as a char.
Last edited on
ok I changed it to be an integer but now it outputs 0s for everything
Isn't the 48th ascii the same as '0'? Another way would be '\x30' (hex)

Basically the ways for that would be this:

1
2
3
4
5
//assigning ascii code to character
char ch = 48; //Dec
char ch = '\x30'; //Hex
char ch = '\060'; //Oct
char ch = '0'; //character 
Last edited on
You can find all the character codes here:
http://www.theasciicode.com.ar/
Play with the values in the array, or when it outputs as an int or a char to get it to do what you want.
I changed it to
 
int map [6] [6] = {2};
and it outputs 0s
You are assigning 2 to the first element and all the others are uninitialized but since you initialized one the rest are omitted to 0's AFAIK..

It seems to me like you are picking random values anyways are you trying to output integers or characters? By the way the fast way is not always the best way especially when you are creating a map. I think the safest way to initalize an array like you want would be to use a for loop like:

1
2
3
4
5
6
7
for( int row = 0; row < max_rows; ++row )
{
    for( int column = 0; column < max_columns; ++column )
    {
        array[row][column] = '0'; //what ever value you want
    }
}


On a side note you can also use std::fill
http://www.cplusplus.com/reference/algorithm/fill/

or fill_n
http://www.cplusplus.com/reference/algorithm/fill_n/
Last edited on
klay, you need to learn more about arrays.
You can't simply "fill" array with giving only one value. It doesn't work that way.
Try to understand what is going on in your code- line by line - and after you understand what's going on, try to think of a way of solving your problem.

In programming, especially at the beginning of education, there are some things that seem obvious to a human - but aren't obvious to computer. That's sad fact, but once you learn how it works - it's not that hard ;)
I have done this before but it's not working now so I did at one point know how to do this
Topic archived. No new replies allowed.