This is homework so I am not looking for a better way to do this. I am only asking for a second pair of eyes to spot my mistake. I have a function that takes a two-dimensional array and fills the first row with the elements from a one-dimensional array. It is then supposed to fill the remaining row with three times that of the previous row. The first part works but the second part does nothing. Near as I can figure it out it looks as if the second part doesn’t even run. Is it because I need to reset the array after the first loop?
const int NUM_FOUR = 4;
void copyGamma(int matrix[][NUM_FOUR], int src, int list2[]);
int main()
{
int inStock[NUM_TEN][NUM_FOUR];
int gamma[NUM_FOUR] = {11, 13, 15, 17};
// Copy gamma elements to inStock and fill the other elements
// by multiplying by three to each remaining successive row
// print again to show changes
copyGamma(inStock, 0, gamma);
cout << "inStock has the following elements: " << endl;
printMatrix(inStock, NUM_TEN);
system("pause");
return 0;
}
// (d) Function that sets the elements of the first row of inStock to gamma and the remaining
// rows to three times the previous row without modifying the elements of gamma
void copyGamma(int matrix[][NUM_FOUR], int numRows, int list[])
{
int row, col;
int nextRow = 1;
for (col = 0; col < NUM_FOUR; col++)
matrix[0][col] = list[col];
// something here to rest array perhaps?
for (row = 0; row < numRows; row++)
{
for (col = 0; col < NUM_FOUR; col++)
matrix[(nextRow)][col] = matrix[(row)][col] * 3;
nextRow++;
}
}
This is due tomorrow so I am not expecting to have this working correctly by then but I sure would like to know where I went wrong. Any help would be appreciated. Not looking for someone to do my homework just need advice on what I have wrong. Thanks