i have a 6x6 array . a certain object randomly moves within the boxes , i need to count the steps he makes for him to able to step all the boxes , i dont know what to do nxt with my code . the dot represents the boxes :

# include <stdio.h>
#include <stdlib.h>
#include <conio.h>
# include <time.h>


time_t seed;

main()
{
clrscr();
seed = time(NULL);
srand(seed);

char box[6][6];
char objct= '*';

int a,b,c;
for (a=0; a<6; a++) {
	for (b=0; b<6; b++) {
		box[a][b]='.';
		box[4][3]='*';
		printf("%c", box[a][b]);
	}
	printf("\n");
	}

getch();
}

Recommended Answers

All 4 Replies

Neither do we since we didn't write it and don't know know what else you want to do with it.

It would be better if you explain more elaborately the desired output of your code

Here is the detail of theCompiler's program

He's having a problem with the coding so maybe you can help him out by suggesting an approach or an algorithm to his problem

A bug is placed on a given square in the middle of a tile floor in a rectangular room of size n x m tiles. The bug wanders randomly from tile to tile throughout the room. Assuming that he may move from his present tile to any of the eight tiles surrounding him (unless he is against a wall) with equal probability, how long will it take him to touch every tile on the floor at least once?


An array N X M is used to represent the number of times bug has reached each tile on the floor. All the cells of this array are initialized to zero. The position of the bug on the floor is represented by the coordinates (IBUG,JBUG)The 8 possible moves of the bug are represented by the tiles located at (IBUG + IMVE(K), JBUG + JMVE(K)) where 1<= K<= 8 and:


IMVE(1) = -1 JMVE(1) = 1

IMVE(2) = 0 JMVE(2) = 1

IMVE(3) = 1 JMVE(3) = 1

IMVE(4) = 1 JMVE(4) = 0

IMVE(5) = 1 JMVE(5) = -1

IMVE(6) = 0 JMVE(6) = -1

IMVE(7) = -1 JMVE(7) = -1

IMVE(8) = -1 JMVE(8) = 0
A random walk to one of the 8 given squares is simulated by generating a random value for K lying between 1 and 8. Of course the bug cannot move outside the room, so that coordinates which lead up a wall must be ignored and a new random combination formed. Each time a square is entered, the count for that square is incremented so that a non-zero entry shows the number of times the bug has landed on that square so far. When every tiles has been step the program ends

program MUST:

1) Handle values of N and M

2 < N<= 40

2 <M<= 20

2) Perform the experiment for

a) N = 15, M = 15 starting point: (20,10)

b) N = 39, M = 19 starting point: (1,1)

3) Have an iteration limit, that is, a maximum number of squares the bug may enter during the experiment. This assures that your program does not get "hung" in an "infinite" loop. A maximum of 50,000 is appropriate for this lab.

4) For each experiment print: a) the total number of legal moves which the cockroach makes; b) the final KUNT array. This will show the "density" of the walk, that is the number of times each tile on the floor was touched during the experiment.

Here is the detail of theCompiler's program

He's having a problem with the coding so maybe you can help him out by suggesting an approach or an algorithm to his problem

If theCompiler confirms your assumption, we can further help him, if he also explains what help he needs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.