私には解決できないような深刻な問題があります。本当に初心者のような問題でしたら、申し訳ありません。
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 です。
私は必ずしも理解していません。誰かが私を助けてくれますか?ありがとう。