Click here to Skip to main content
15,794,275 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to add the value of all the items and then divide on total number items, where my mistace?

What I have tried:

int Whether(int num_years)
    int i, sum = 0;
    for (i=0; i
Updated 12-Dec-22 1:03am

1 solution

We can't see your whole code: just a fraction of it.

But ... if you are meant to take an array and get the average then you need to pass two pieces of information into your function: the array itself, and the number of items in it.
Then it's trivial:
int Average(int data[], int len)
   int sum = 0;
   for (int i = 0; i < len; i++)
      sum += data[i];
   return sum / len;
Share this answer
CPallini 12-Dec-22 6:09am    
I can see just the whole of your result, not the fraction of it.
OriginalGriff 12-Dec-22 6:28am    
That's because it's all integers ... :D
CPallini 12-Dec-22 6:49am    
Nobody can argue with an integer man!
OriginalGriff 12-Dec-22 7:02am    
Real men do!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900