So i am back again, working with arrays this time. I can get it to run in the main but i am not sure how to make this code into a void function .
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main ()
{ // Declare variables and initialize
const int monkeytot = 3;
const int Wdays = 7;
int monkeys;
int days;
int most = 0;
int least = 0;
int total = 0;
double average = 0;
double totaleaten;
double food [monkeytot][Wdays];
// start program
// Fill array with numbers
for (monkeys = 0; monkeys < monkeytot; monkeys++)
{
for (days = 0; days < Wdays; days++)
{
cout << " Enter pounds of food eaten by monkey " << (monkeys + 1)<< ", Day " << (days + 1) << ": ";
cin >> food[monkeys][days];
cout << food[monkeys][days];
}
cout << endl;
}
return 0;
}
i tried this: but when it compiles it says food not declared in scope. I have put food[monkeys][Wdays] with and without the double, but i am not sure how to call the function in int main. the book i am using doesn't really explain for 2d arrays
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void monkeyfood ()
{ // Declare variables and initialize
const int monkeytot = 3;
const int Wdays = 7;
int monkeys;
int days;
double food[monkeys][Wdays];
// Fill array with numbers
for (monkeys = 0; monkeys < monkeytot; monkeys++)
{
for (days = 0; days < Wdays; days++)
{
cout << " Enter pounds of food eaten by monkey " << (monkeys + 1)<< ", Day " << (days + 1) << ": ";
cin >> food[monkeys][days];
cout << food[monkeys][days];
}
cout << endl;
}
};
int main ()
{ // Declare variables and initialize
const int monkeytot = 3;
const int Wdays = 7;
int monkeys;
int days;
int most = 0;
int least = 0;
int total = 0;
double average = 0;
double totaleaten;
// start program
}