Thread: help programing in c

  1. #16
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    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
    Fact - Beethoven wrote his first symphony in C

  2. #17
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Cross post
    Board Message
    Fact - Beethoven wrote his first symphony in C

  3. #18
    Registered User
    Join Date
    May 2019
    Posts
    10
    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);
    }
    Last edited by Salem; 05-29-2019 at 10:58 PM. Reason: Move question out of code

  4. #19
    Registered User
    Join Date
    May 2019
    Posts
    10
    Quote Originally Posted by Click_here View Post
    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. #20
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by Jairofr View Post
    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...
    Fact - Beethoven wrote his first symphony in C

  6. #21
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    This also might help you get more meaningful answers
    How to ask questions the smart way
    Fact - Beethoven wrote his first symphony in C

  7. #22
    Registered User catacombs's Avatar
    Join Date
    May 2019
    Location
    /home/
    Posts
    81
    FYI: I saw this exact question in Dream.In.Code. Yet another help vampire.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. new to C programing, need a little help
    By mgrenier25 in forum C Programming
    Replies: 10
    Last Post: 01-22-2014, 07:25 PM
  2. DNA C programing
    By S16 in forum C Programming
    Replies: 2
    Last Post: 04-29-2009, 09:54 AM
  3. new to programing need help!!
    By newguy3121 in forum C++ Programming
    Replies: 18
    Last Post: 09-21-2006, 01:59 PM
  4. programing in DOS?
    By k1ll3r in forum C++ Programming
    Replies: 41
    Last Post: 05-31-2006, 04:17 AM
  5. programing
    By NiVaG in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-03-2004, 09:19 AM

Tags for this Thread