# Help! Pleaaaaaaaase :)))))

Discussion in 'C' started by Angelli, Dec 5, 2012.

1. ### AngelliNew Member

Joined:
Dec 5, 2012
Messages:
4
0
Trophy Points:
0
A drunken cockroach is placed on the middle of a tile floor in a rectangular room that has N by M tiles. Searching for an aspirin, the bug wanders aimlessly from tile to tile throughout the room. Assuming that the cockroach may move from his present tile to any of the eight tiles surrounding him (unless he is against a wall) with equal probability, write a MODULARIZED program that stimulates the bugâ€™s search for the aspirin.

Input N and M from the keyboard. The aspirin is randomly placed on a tile. Randomly generate integers from 1 to 8 to determine the cockroachâ€™s next move. Use the following convention.

Random number Bugâ€™s direction

1 North

2 Northeast

3 East

4 Southeast

5 South

6 Southwest

7 West

8 Northwest

As the bug wanders looking for aspirin, store successive integers in a FLOOR array indicating the tiles he crawled over. You will need to check if he bumps into walls and may have to generate additional numbers to get him on his way again.

Output is to consist of the floor dimensions (N and M), the initial location of the cockroach, the location of the aspirin, and a table representing the floor with his random walk recorded. I expect appropriate headings and a nicely formatted table in the output. I expect commenting, Indenting, and the use of white space. Test appropriately.

Requirements:

1. Use a two-dimensional array for this problem. Make the program solve by showing every possible solution.

2. ### AngelliNew Member

Joined:
Dec 5, 2012
Messages:
4
0
Trophy Points:
0
I'm a newbie with C language that's why I'm begging you to help me out with this problem. Thank you in advance! =))))))

3. ### hobbyistNew Member

Joined:
Jan 7, 2012
Messages:
141
0
Trophy Points:
0
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <time.h>

declare any function prototypes / defintions

int main(void) {

declare required vars

do {

verify they're valid, if so
initialize the floor array
place roach in middle

while(food coords are invalid or overlay roach) {
get new random aspirin coords
}

place aspirin

while(roach hasn't found aspirin) {

get a direction
check if roach can move, if so
update steps taken from old roach coords
compute new roach coords and move
if not,
check for aspirin, if found
show appropriate output
prompt for new game
}

} while(player wants to play);

output program termination message
...
}```
maybe something along those lines. give it a try.

4. ### AngelliNew Member

Joined:
Dec 5, 2012
Messages:
4
0
Trophy Points:
0
Thank you! I'll try it out! ))