c++ passing 2d arrays to funcions

后端 未结 2 1193
既然无缘
既然无缘 2021-01-23 09:02

I know my code isnt finished yet im not asking for it to be done. It\'s supposed to input food eaten by 3 monkeys over a week and other stuff. But I\'ve hit a snag. It gives me

2条回答
  •  感动是毒
    2021-01-23 09:51

    you declare:

    const double array[][DAYS],
    

    however, inside poundsEaten function, you are asking user to input information to fill in the array, which means the array is not const, therefore, error. Remove the const qualifier from the parameter such that the array can be changed by user input.

    void poundsEaten(double array[][DAYS], int rows, int cols)
    

    BTW: don't use array as variable name for an array, use some other names for good practice. Meanwhile,cols is not used inside your poundsEaten function.

提交回复
热议问题