Here are the rules for the program...
(1) Create a function that displays a two dimensional array. The example uses a
35 X 35 array. If the stored value is 0, show “.”, otherwise show the stored
number. Hint: Use two dimensional array, nested loops, and if statement.
(2) In the main program, set the randomly selected starting locations for each
number /animal. The example uses number 1 through number 6.
(3) Move each number/animal so that an animal chases the next animal. For
example, animal # 1 chases animal # 2, animal # 2 chases animal # 3, and
animal # 6 (the last animal) chases animal # 1(the first animal). Hint: Use
modulus division, as well as if statements. You may choose the direction of
the movement to either four directions or eight directions.
(4) Repeat Number 3 at least 20 times. Show the trace of each animal’s
numbers. Hint: Use a loop. You may use system("CLS"); to clear the
screen, and system("pause"); to pause after each iteration.
-----------------------------------------------------------------------
This is what i have so far...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int array[10][10] = { 0 };
int i, j;
array[1][1] = { 5 };
array[8][8] = { 3 };
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
if (array[i][j] < 1)
cout << '.';
else
cout << array[i][j];
cout << " ";
}
cout << endl;
}
}
| |
I am not sure what i should do after i have created my field. I am trying to get number "5" and "3" to chase after each other for about 20 pause iterations. I made the field and about of animals(numbers) less than the actual assignment requirements for ease of understanding.