我有一个严重的问题,我似乎无法解决。如果这是一个非常像新手的问题,我深表歉意。
srand(117);
//enumeration type to keep track of which fish is which
enum CellState {EMPTY, FISH, SHARK};
//Creating the grid
CellState fishGrid[MAX_X][MAX_Y];
for(int m = 0; m < MAX_X; ++m)
{
for(int n = 0; n < MAX_Y; ++n)
{
int num = rand() % 2;
if(num == 0)
fishGrid[m][n] = EMPTY;
else
{
num = rand() % 2;
if(num == 0)
fishGrid[m][n] = SHARK;
else
fishGrid[m][n] = FISH;
}
}
}
//calculate how many on grid
if(stepsTaken % 5 == 0)
{
int fishAmount = 0;
int sharkAmount = 0;
for(int m = 0; m < MAX_X; m++)
{
for(int n = 0; n < MAX_Y; n++)
{
if(fishGrid[m][n] = FISH)
fishAmount++;
else if(fishGrid[m][n] = SHARK)
sharkAmount++;
}
}
cout << "FISH: " << fishAmount << endl
<< "SHARKS: " << sharkAmount << endl << endl;
由于某种原因,输出总是: FISH: 100 SHARKS: 0
我不一定明白。有人可以帮助我吗?谢谢。