Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* readline();
char* ltrim(char*);
char* rtrim(char*);

int parse_int(char*);



/*
 * Complete the 'calculateAverage' function below.
 *
 * The function is expected to return an INTEGER.
 * The function accepts INTEGER_ARRAY numbers as parameter.
 */

int calculateAverage(int numbers_count, int* numbers) {

}

int main()


What I have tried:

trying to figure it out the old fashion way
Posted
Comments
Mike Hankey 23-Sep-23 15:04pm    
We did our homework years ago, now it's your turn.
We will help if you make an effort and get stuck somewhere.
Dave Kreskowiak 23-Sep-23 18:04pm    
Well, calculating averages is taught in 4th grade math, so I hope that's not the problem.

Doing it in code is very easy and you've been given the tools know how to do that in your coding class.

Quote:
trying to figure it out the old fashion way

Remember: Google is your friend.
Average - Wikipedia[^]
Calculating an average is really simple thing. If your are not sure about how to translate in code, experiment/ try things and see the results you get, some of them may be useful and be partial solutions which show you the path to solution.

The problem is that programming computer is about you being creative, and an average is extremely simple problem.
If really you are coming up with nothing, you need to talk with your teacher.
If you really need us to give you the solution of such a simple problem, it means that the job is not for you.
 
Share this answer
 
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

In this case, all you need is to add up all the values, and divide that total by the number of values and return the number you get as a result. You will need a loop to look at each value, and I'd recommend that you use a long value to add them up because the total cane be considerably higher than the largest value in an integer!

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

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