please debug my small program

I want program to first run and print spaces in all values of array. Then it should print the ascii characters on their mentioned positions.I am getting to errors please remove them


#include <iostream>
using namespace std;

void main()
{
char bot[24][79];



for(int i=0;i<24;i++)
{
for (int j=0;j<79;j++)
{
bot[i][j]=32;
cout << bot[i][j];
}

char bot[24][79];

bot[18][3]=92;
bot[18][1]=94;
bot[19][2]=153;
bot[20][1]=95;
bot[20][2]=124;
bot[20][3]=95;
bot[21][2]=124;
bot[22][1]=47;
bot[22][3]=92;

for( i = 0; i <24; i++)
{
for( j=0;j<79;j++)


cout << bot[i][j] ;
cout << endl;
}

}
}
You have:

1. a misplaced bracket
2. a valiable defined twice (you can only define a variable once!)
3. two missing variables (assuming you are not using an old version of VC++, like VC++ 6.0)

 ^ \
  Ö
 _|_
  |
 / \

If you go back and format your post using [code]// your code here! [/code] tags, and then

(a) fix your brackets (counting them is easy if you've indented consistently
(b) remove the duplicate variable
(c) add the two missing variables

Then it should "just" work!

Commenting out some of you code with /* your unwanted code */ might help. Also, it's good style for main() to return 0, even if you can get away without doing so.

Andy

How to use code tags
http://www.cplusplus.com/forum/articles/42672/
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
#include <iostream>
using namespace std;

int main()
{
char bot[24][79];



  for(int i=0;i<24;i++)
  {
for (int j=0;j<79;j++)
{
bot[i][j]=32;
cout << bot[i][j];
}

char bot[24][79];

bot[18][3]=92;
bot[18][1]=94;
bot[19][2]=153;
bot[20][1]=95;
bot[20][2]=124;
bot[20][3]=95;
bot[21][2]=124;
bot[22][1]=47;
bot[22][3]=92;

for(int i = 0; i <24; i++)
{
for(int j=0;j<79;j++)
cout << bot[i][j];

cout << endl;
}

  }


}



I fix your program,but you should make your program better.
It is uselless and crash cmd.
@skarla

The code you posted is not correctly corrected!

(In particular, the bracketing is still wrong. The little stick man above is the o/p of the fixed code, without crash.)

Andy
Last edited on
@skarla,
I think all you did was put in a curly brace so that it would compile.

The point you missed is, the loop is 2nd innermost i and j loop is enclosed in the outer i,j loop which he was using it initilize the bot[][] array. in the end, you're printing out the bot array 24x79 times.

all you really needed to do is this:
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
int main()
{
    char bot[24][79];

    for(int i=0; i<24; i++)
        for (int j=0; j<79; j++)
            bot[i][j]=32;

        //char bot[24][79];

        bot[18][3]=92;
        bot[18][1]=94;
        bot[19][2]=153;
        bot[20][1]=95;
        bot[20][2]=124;
        bot[20][3]=95;
        bot[21][2]=124;
        bot[22][1]=47;
        bot[22][3]=92;

    for(int i=0; i<24; i++)
        for (int j=0; j<79; j++)
        cout << bot[i][j];

}
Topic archived. No new replies allowed.