- Joined
- Mar 5, 2005
- Location
- Illinois
I'm currently in an intro C++ course in college and I'm working on an assignment in which I need to pass a two-dimensional array to a function. (The program is one a theoretical zookeeper would use to keep track of how much food monkeys are eating over the course of a week).
Now the book has me creating two global constants for the rows and columns:
I've left out bits of the code irrelevant to my question.
We've pretty much been taught to avoid global variables like the plague, but of course the book does it a different way. How would I have to alter the function prototype/header in order to allow me to move the constants to main?
Now the book has me creating two global constants for the rows and columns:
Code:
#include <iostream>
using namespace std;
const int MONKEYS = 3;
const int DAYS = 7;
int main()
{
// Function prototype
void getFoodEaten(double [][DAYS]);
// Declare array
double food[MONKEYS][DAYS];
// Get the food amount eaten
getFoodEaten(food);
}
void getFoodEaten(double food[][DAYS])
{
// Insert code here
}
I've left out bits of the code irrelevant to my question.
We've pretty much been taught to avoid global variables like the plague, but of course the book does it a different way. How would I have to alter the function prototype/header in order to allow me to move the constants to main?
Last edited: