Arrays: mean, largest value, function count,

• 04-19-2006
aryanthegreat
Arrays: mean, largest value, function count,
Hi everyone, I need a bit of help in this assignment I need to hand in for university. Can anyone help me? here is the problem:-

"Read a program that will read in a file of integers into an array. Hence, writing your own functions, compute their mean, the largest value, and a function count to count how many times an integer occurs int he data. Output your results to a file aswell as the screen."

*Apparently these arays must also be read from a text file*

If anyone has any ideas I will be very greatful for your comments and help.

I know that something like this should be in it (I wrote most of this down, my lecturer edited it for me), but can anyone by any chance give me the codes to help complete this assignment.

PHP Code:

``` #include <iostream.h> void main() { float myArray[100]; int last, i; for (i=0; i<=99; i=i+1) { float mean (float A[],int Size)      ***********************         {         float mean;         float sum = 0;         for (int i=0; i < Size; i=i+1);                 {                 sum = sum + A[i];         } //end loop                 mean = sum/(Size);         return mean;         }//end loop    +++++++++++++++++ }  //end loop last =i-1; for (i=0; i<=last; i=i+1) { cout << "X[i]" << " "; } //end loop }//end main  ```
A quote my lecturer sent me through his email says;

"The lines from the **** to the ++++ are a function defintion and should be AFTER the end of the main program. You aonly need to call the mean function in the main program

e.g. cout << Mean(X,size) "

THANKS AND KIND REGARDS

ARYAN
• 04-19-2006
Ideswa
mean() is a function, like main. It must be out of the { and } of the main function. Main returns an int. Use std:: before cout. or put "using namespace std;" under the includes. Format your code. iostream.h is outdated, use iostream. It's a weird code, what is the "Size" variable? What's that "X" array?

Code:

```#include <iostream> using namespace std; float mean(float A[], int Size); int main() {     float myArray[100];     int last, i;     for (i=0; i < 99; i++) // i = i + 1 is the same as i++     {         mean(myArray, i) // what variable is "Size"?     }     last =i-1;     for (i=0; i <= last; i++)     {         cout << X[i] << " "; // don't quote around variables     } //end loop     return 0; } float mean (float A[], int Size)      // what variable is Size? {     float m;     float sum = 0;     for (int i=0; i < Size; i++) // wrong semi-colon,     {         sum = sum + A[i];     }           m = sum/Size;     return m; }```
• 04-19-2006
aryanthegreat
the set of arrays ca be any random amount of numbers as longh asd its read from a file, im also not quite sure of the 'Size' variable, could you elaborate what that means a little bit.

So how would I read a set of arrays from a txt file, and where would i put it?

Thank you so much

KIND REGARDS ARYAN
• 04-19-2006
Ideswa
You should read some cprogramming.com tutorials

All about filestreaming, too. You should read the basics again, because you had a lot of syntax errors. Don't you try to compile codes before you post them?
• 04-19-2006
aryanthegreat
i had done actually but i thought i would put it in alond with my errors so peple coud help rectify my mistakes.