Multidimenshonal Array problem

Hello can someone check my code becaus eI'm getting errors i don't know how to fix

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 <Windows.h>
using namespace std;

const int ROW(10);
const int COLUMN(10);

string ARRAY [ROW][COLUMN];

int HM;
int HeroPosX(5), HeroPosY(5);
// X = --   Y = |
// Border is on a 10 X 10 Resolution

// 1 = UP, 2 = DOWN, 3 = LEFT, 4 = RIGHT

void Border ()
{
	int Col1, Row1;
	for(Col1 = 0; Col1 <= 10; Col1 += 10)
		for (Row1 = 0; Col1 <= 10; Col1 += 10)
			ARRAY[Row1][Col1] = "#";
	cout << endl;
}
void Fill   ()
{
	// A = Row, B = Column
	int A, B;
	for (A = 1; A <=9; A++)
		for (B = 1; B <= 9; B++)
			ARRAY[A][B] = " ";
	cout << endl;
}
void Hero   ()
{

	if (HM == 1)
	{
		ARRAY[HeroPosX][HeroPosY] = " " ;
		HeroPosX--;
		ARRAY[HeroPosX][HeroPosY] = "H";
		HM = 0;
	}
	else if (HM == 2)
	{
		ARRAY[HeroPosX][HeroPosY] =  " ";
		HeroPosX++;
		ARRAY[HeroPosX][HeroPosY] =  "H";
		HM = 0;
	}
	else if (HM == 3)
	{
		ARRAY[HeroPosX][HeroPosY] = " " ;
		HeroPosY--;
		ARRAY[HeroPosX][HeroPosY] = "H";
		HM = 0;
	}
	else if (HM == 4)
	{
		ARRAY[HeroPosX][HeroPosY] = " " ;
		HeroPosY++;
		ARRAY[HeroPosX][HeroPosY] = "H" ;
		HM = 0;
	}
	else
	{

	}

}
void Print  ()
{
	int Row, col;
	for (Row = 0; Row < ROW; Row++)
		for (col = 0; col < COLUMN; col++)
			cout << ARRAY[Row][col] << "\t";
	cout << endl;
}
int main    ()
{
	//Set border
	Border ();
	Fill   ();
	Print  ();
	system("pause");
}
What are your errors?

Print can be improved:
1
2
3
4
5
6
7
8
9
10
11
void Print  ()
{
	int Row, col;
	for (Row = 0; Row < ROW; Row++)
	{
		for (col = 0; col < COLUMN; col++)
			cout << ARRAY[Row][col] << "\t";
		cout << endl;
	}
	cout << endl;
}


Fill() uses:
1
2
	for (A = 1; A <=9; A++)
		for (B = 1; B <= 9; B++)

It probably should be:
1
2
	for (Row = 1; Row < ROW-1; Row++)
		for (col = 1; col < COLUMN-1; col++)


Border() should probably just do the borders:
1
2
3
4
5
6
7
8
9
10
11
12
	Row1=0;
	for(Col1 = 0; Col1 < COLUMN; Col1++)
		ARRAY[Row1][Col1] = "#";
	Row1=ROW-1;
	for(Col1 = 0; Col1 < COLUMN; Col1++)
		ARRAY[Row1][Col1] = "#";
	Col1=0;
	for(Row1 = 0; Row1 < ROW; Row1++)
		ARRAY[Row1][Col1] = "#";
	Col1=COLUMN-1;
	for(Row1 = 0; Row1 < ROW; Row1++)
		ARRAY[Row1][Col1] = "#";
Last edited on
1>------ Build started: Project: Array Game, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\users\josh\documents\visual studio 2010\projects\array game\array game\main.cpp(77): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(726): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(764): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(811): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(937): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(944): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(951): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(958): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(968): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>,std::string>(std::basic_ostream<_Elem,_Traits> &&,_Ty)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ty=std::string
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(1085): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)'
1> with
1> [

1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(260): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(280): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(int)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(305): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(325): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(345): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(366): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(386): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(407): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(427): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(447): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(467): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(487): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> while trying to match the argument list '(std::ostream, std::string)'
Missing:
#include <string>
O thanks... so basic
Topic archived. No new replies allowed.