### Help with pointing arrays (simple...)

In the temp array the first box represents the days and the second is the hour of the day.

I need to average the total temperature for the day in the function "GetAvTime"

-How can I use my user defined "day1" in my array in my function?

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849`` `````` #include #include #include #include using namespace std; void GetAvTime (int temp, int day1) { int k = day1, int average; for (int y = 0; y < 25; y++) { temp [k][y]; average += y; return; } int main () { int day1; int random; int temp[7][24]; srand (time(NULL)); random = rand() %50 + 50; for (int i = 0; i < 7; i++) { for (int j = 0; j < 24; j++) { random = rand() %50 + 50; temp [i][j] = random; } } cout << "Enter Day." << endl; cin >> day1; if (day1 < 0 || day1 > 7) { cout << "Invalid Parameters. Press any key to exit." << endl; exit(1); } cout << endl; GetAvTime (temp[7][24], day1); return 0; } ``````
Last edited on
 ``12345678`` ``````int GetAvTime (int temp[][24], int day) { int average = 0; for ( int k = 0; k < 24, k++ ) average += temp[day][k]; return ( average /= 24 ); }``````
Last edited on
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````# include # include # include using namespace std; void GetAvTime (int *ptr) { int average = 0; for(int i=0;i<24;i++) { average += *ptr++; } average /= 24; cout << "The average temp is : " << average << endl; } int main () { int day1; int random; int temp[7][24]; srand (time(NULL)); random = rand() %50 + 50; for (int i = 0; i < 7; i++) { for (int j = 0; j < 24; j++) { random = rand() %50 + 50; temp [i][j] = random; } } cout << "Enter Day." << endl; cin >> day1; cout << endl; GetAvTime(temp[day1]); return 0; }``````

Thanks, but one last thing.

it says:
"Arguement type of int is incompatible with parameter of type int [*][24];

on line 45

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````#include #include #include #include using namespace std; int GetAvTime (int temp[][24], int day) { int average = 0; for ( int k = 0; k < 24; k++ ) average += temp[day][k]; return ( average /= 24 ); } int main () { int day1; int random; int temp[7][24]; srand (time(NULL)); random = rand() %50 + 50; for (int i = 0; i < 7; i++) { for (int j = 0; j < 24; j++) { random = rand() %50 + 50; temp [i][j] = random; } } cout << "Enter Day." << endl; cin >> day1; if (day1 < 0 || day1 > 7) { cout << "Invalid Parameters. Press any key to exit." << endl; exit(1); } cout << endl; GetAvTime (temp[7][24], day1); return 0; }``````
 ``12`` `````` std::cout << "The average temperature for day " << day1 << " is " << GetAvTime (temp, day1) << std::endl;``````

Last edited on
Int k = day1 is not an int

fix:

// k= day 1
int k = 1
Topic archived. No new replies allowed.