# Thread: help programing in c

1. Oh, I'm not going to be doing it for you. I think that you'll find my prices unreasonably expensive :P

I just can't understand how it was ever expected to compile. So many errors!

I'd suggest scrapping the code and starting again, and then building the code back up incrementally - It won't take that long, but it will be a better foundation

Step 1 - Open file, print first line and close.
Step 2 - print the whole file

Seporately...
Step 3 - make a function that can calculate the mean value from preset array.
Step 4 - make a function that can calculate the median value from preset array.

Step 5 - put mean function in the original code and pass values from the file to it and print it out
Step 6 - put median function in the original code and pass values from the file to it and print it out

2. Cross post
Board Message

3. I have to do in the code from the numbers of txt me of the result of the calculation of the formulas of the mean and the median. I have many mistakes can you help me please.
Code:
```#include <stdio.h>
#include <conio.h>
#include <string.h>

main
{

FILE *fp1,*fp2;
int i;
float A[4];
fp1 = fopen("datos.txt", "r");   //Abrimos  el archivo

for(i=0;i<4;i++)                 //Iteramos i para  ir almacenando los valores.
{
fscanf(fp1, "%f", &A[i]);        // Leemos un float y lo guardamos en A en la posicion i

printf("Media [% d]: %.2f \n",i, A[i]);
}

{
printf("ponga el numero y despues enter");
int  x[100],n,i ;
float  mean (int,int []);
float  mediana (int,int []);

scanf ("%d",&n);
for (i=0;i<n;i++)
scanf("%d",&x [i]);
printf ("media=%f\n ",mean(n,x));
printf ("mediana=%f\n",mediana (n,x));
getch ();

}

float  mean (int m,int a [])  {
int  sum= 0,i;
for (i=0;i<m;i++ )
sum+=a[i];
return ((float)sum/m );
}

float  mediana ( int n, int x [])  {
float  temp ;
int i,j;
for ( i=0;  i<n-1;i ++ )  {
for (j=i+1;j<n;j++)  {
if (x[j]<x[i])  {
temp=x[i];
x [i]=x[j];
x [j]= temp ;
}
}
}

if (n%2==0)  {
return((x[n/2]+x[n/2-1])/2.0);
}
else
{

return x[n/2];

}
}
fclose(fp1);
}```

4. Originally Posted by Click_here
Oh, I'm not going to be doing it for you. I think that you'll find my prices unreasonably expensive :P

I just can't understand how it was ever expected to compile. So many errors!

I'd suggest scrapping the code and starting again, and then building the code back up incrementally - It won't take that long, but it will be a better foundation

Step 1 - Open file, print first line and close.
Step 2 - print the whole file

Seporately...
Step 3 - make a function that can calculate the mean value from preset array.
Step 4 - make a function that can calculate the median value from preset array.

Step 5 - put mean function in the original code and pass values from the file to it and print it out
Step 6 - put median function in the original code and pass values from the file to it and print it out
Friend is not a matrix is ​​to calculate the average and the median still does not come out help me

5. Originally Posted by Jairofr
Friend is not a matrix is ​​to calculate the average and the median still does not come out help me
I didn't say anything about a matrix - My advice was to start again and rebuild it in small steps.

You didn't seem to respond in a way to suggest that you wanted to do that, so I stopped helping.

PS - I don't think that flooding the board with the same question is going to go down well...

6. This also might help you get more meaningful answers
How to ask questions the smart way

7. FYI: I saw this exact question in Dream.In.Code. Yet another help vampire.

Popular pages Recent additions