+ 2

Average Age question in Pointers in Introduction to C++

Please help me solve the errors in this code #include <iostream> using namespace std; int main() { int ages[] = {19, 24, 36, 45, 56, 52, 21, 27, 24, 34, 29, 60, 40, 42, 45, 47, 22, 30, 34, 20, 18, 26, 51, 43, 47, 39, 22, 34, 56, 52, 21, 27, 24, 37, 19, 24, 36, 45, 44, 49, 23, 25, 19, 40, 29, 60, 40, 42, 45, 47, 61, 30, 19, 43, 47, 39, 41, 46, 29, 24, 21, 25, 28}; int size = 63; int sum = 0; int *p = ages; for(int i=0;i<size;i++) { cout << *p << endl; sum += *p; p++; } int average = sum / size; cout << average; }

18th Dec 2023, 2:46 PM
Aatif Shaikh
Aatif Shaikh - avatar
1 Respuesta
+ 9
Aatif Shaikh , there is a line of *code given from sololearn* that is *not needed*: the task description says: *You do not need to output the array.* cout << *p << endl; comment this line out and your code will run.
18th Dec 2023, 4:37 PM
Lothar
Lothar - avatar