Thread: not sure what i am doing wrong.

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    12

    not sure what i am doing wrong.

    The requirement for this project is
    1)double calculate_deviation (double number, double mean) - Determines the deviation of number from the mean and returns the result. The deviation may be calculated as number - mean.

    2)double calculate_variance (double deviation1, double deviation2, double deviation3, double deviation4, double deviation5, int number) - Determines the variance through the calculation: ((deviation1)^2 + (deviation2)^2 + (deviation3)^2 + (deviation4)^2 + (deviation5)^2) / number


    3)double calculate_standard_deviation (double variance) - Calculates the standard deviation as sqrt (variance) and returns the result


    [FILE WHERE I AM GETTING MY INFORMATION ON]
    12345678-student id
    3.78-gpa
    3-class standing
    20.5-age

    87654321
    2.65
    2
    19.25

    08651234
    3.10
    1
    18.0

    11112222
    3.95
    4
    22.5

    22223234
    2.45
    3
    19.3333



    Code:
    [SOURCE.C FILE]
    double compute_deviation_gpa(double gpa1, double gpa2, double gpa3, double gpa4, double gpa5,double gpa_mean) {
        double deviation_gpa1 = 0.0;
        double deviation_gpa2 = 0.0;
        double deviation_gpa3 = 0.0;
        double deviation_gpa4 = 0.0;
        double deviation_gpa5 = 0.0;
        deviation_gpa1 = gpa1 - gpa_mean;
        deviation_gpa2 = gpa2 - gpa_mean;
        deviation_gpa3 = gpa3 - gpa_mean;
        deviation_gpa4 = gpa4 - gpa_mean;
        deviation_gpa5 = gpa5 - gpa_mean;
        return deviation_gpa1;
        return deviation_gpa2;
        return deviation_gpa3;
        return deviation_gpa4;
        return deviation_gpa5;
    }
    double compute_variance(double deviation_gpa1, double deviation_gpa2, double deviation_gpa3, double deviation_gpa4, double deviation_gpa5, double number) {
        double variance = 0.0;
        number = 5;
        ((deviation_gpa1*deviation_gpa1) + (deviation_gpa2*deviation_gpa2) + (deviation_gpa3*deviation_gpa3) + (deviation_gpa4*deviation_gpa4) + (deviation_gpa5*deviation_gpa5) / number);
        return variance;
    
    
    }
    double compute_standard_deviation(double variance) {
        double standard_d = 0.0;
        standard_d = sqrt(variance);
        return standard_d;
    }
    
    
    
    [MAIN.C FILE]
    compute_deviation = compute_deviation_gpa( gpa1, gpa2,  gpa3,  gpa4,  gpa5, gpa_mean);
        compute_variancee = compute_variance(deviation_gpa1, deviation_gpa2, deviation_gpa3, deviation_gpa4, deviation_gpa5, number);
        compute_sd = compute_standard_deviation(variance);
        
        fprintf(outfile, "sd %.2lf\n ", compute_sd);
        
        return 0;
    whenever i run this, i get zero. I am not sure why.
    Any help is appreciated, thank you.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Talking about your compute_deviation_gpa function, you can't return multiple values like this. Consider passing an array to the function in order to save the values for later use.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Sep 2017
    Posts
    12
    I have not learned about array; however, your answer has helped me. I can not believe i forgot about that. Thank you very much.

  4. #4
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by brianjoo View Post
    The requirement for this project is
    1)double calculate_deviation (double number, double mean) - Determines the deviation of number from the mean and returns the result. The deviation may be calculated as number - mean.

    2)double calculate_variance (double deviation1, double deviation2, double deviation3, double deviation4, double deviation5, int number) - Determines the variance through the calculation: ((deviation1)^2 + (deviation2)^2 + (deviation3)^2 + (deviation4)^2 + (deviation5)^2) / number


    3)double calculate_standard_deviation (double variance) - Calculates the standard deviation as sqrt (variance) and returns the result
    you will have to be the judge on the math if this works or not.

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    
    int   compute_deviation_gpa(double * gpa1, double * gpa2, double * gpa3, double * gpa4, double * gpa5, double * gpa_mean)
    
    {
    
        printf(" 1::IN C DEVATION %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n", *(double*)gpa1, *(double*)gpa2, *(double*)gpa3, *(double*)gpa4, *(double*)gpa5, *(double*)gpa_mean);
        *gpa1 = gpa1 - gpa_mean;
        *gpa2 = gpa2 - gpa_mean;
        *gpa3 = gpa3 - gpa_mean;
        *gpa4 = gpa4 - gpa_mean;
        *gpa5 = gpa5 - gpa_mean;
    
        printf("2:: IN C DEVATION %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n", *(double*)gpa1, *(double*)gpa2, *(double*)gpa3, *(double*)gpa4, *(double*)gpa5, *(double*)gpa_mean);
        return 0;
    }
    double compute_variance(double deviation_gpa1, double deviation_gpa2, double deviation_gpa3, double deviation_gpa4, double deviation_gpa5, double number)
    {
        printf("in Compute %f %f %f %f %f %f\n", deviation_gpa1, deviation_gpa2, deviation_gpa3, deviation_gpa4, deviation_gpa5, number);
        //double variance = 0.0;
      // number = 5;
         return( ((deviation_gpa1*deviation_gpa1) + (deviation_gpa2*deviation_gpa2) + (deviation_gpa3*deviation_gpa3) + (deviation_gpa4*deviation_gpa4) + (deviation_gpa5*deviation_gpa5) / number));
    }
    double compute_standard_deviation(double variance) {
        //double standard_d = 0.0;
        //standard_d = sqrt(variance);
    
        return ( sqrt(variance) );
    }
    
    int main()
    {
    
     double gpa1, gpa2,gpa3,gpa4,gpa5, gpa_mean;
     gpa1 = 5.3;
     gpa2 = 2.3;
     gpa3 = 10.3;
     gpa4 = 123456782.3;
     gpa5 = 2.3;
     gpa_mean = 5.0;
     double number = 5.0;
    
    double variance;
    
    double  compute_sd;
    
        compute_deviation_gpa(        &gpa1,                 &gpa2,                 &gpa3,                &gpa4,                &gpa5,  &gpa_mean);
    
        variance = compute_variance(gpa1, gpa2, gpa3, gpa4, gpa5, number);
    
        printf("FF %f\n",compute_variance(gpa1, gpa2, gpa3, gpa4, gpa5, number) );
    
        compute_sd = compute_standard_deviation(variance);
    
            printf( "sd %.2lf\n ", compute_sd);
    
    // I tried to get it to go one inside other but them end vaules on the two functions were getting in my way
    
       // printf("sd %f\n ", compute_standard_deviation(compute_variance( compute_deviation_gpa( &gpa1, &gpa2,  &gpa3,  &gpa4, &gpa5, gpa_mean), 5)));
    
    
    return 0;
    }
    out put

    Code:
     userx@~/bin <> gcc -Wall  -lm devation_gpa.c
    userx@~/bin <> ./a.out
     1::IN C DEVATION 5.30
     2.30
     10.30
     123456782.30
     2.30
     5.00
    2:: IN C DEVATION 5.00
     4.00
     3.00
     2.00
     1.00
     5.00
    in Compute 5.000000 4.000000 3.000000 2.000000 1.000000 5.000000
    in Compute 5.000000 4.000000 3.000000 2.000000 1.000000 5.000000
    FF 54.200000
    sd 7.36
     userx@~/bin <>
    Pass By Reference

  5. #5
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by brianjoo View Post
    The requirement for this project is
    1)double calculate_deviation (double number, double mean) - Determines the deviation of number from the mean and returns the result. The deviation may be calculated as number - mean.

    2)double calculate_variance (double deviation1, double deviation2, double deviation3, double deviation4, double deviation5, int number) - Determines the variance through the calculation: ((deviation1)^2 + (deviation2)^2 + (deviation3)^2 + (deviation4)^2 + (deviation5)^2) / number


    3)double calculate_standard_deviation (double variance) - Calculates the standard deviation as sqrt (variance) and returns the result


    [FILE WHERE I AM GETTING MY INFORMATION ON]
    12345678-student id
    3.78-gpa
    3-class standing
    20.5-age

    87654321
    2.65
    2
    19.25

    08651234
    3.10
    1
    18.0

    11112222
    3.95
    4
    22.5

    22223234
    2.45
    3
    19.3333



    Code:
    [SOURCE.C FILE]
    double compute_deviation_gpa(double gpa1, double gpa2, double gpa3, double gpa4, double gpa5,double gpa_mean) {
        double deviation_gpa1 = 0.0;
        double deviation_gpa2 = 0.0;
        double deviation_gpa3 = 0.0;
        double deviation_gpa4 = 0.0;
        double deviation_gpa5 = 0.0;
        deviation_gpa1 = gpa1 - gpa_mean;
        deviation_gpa2 = gpa2 - gpa_mean;
        deviation_gpa3 = gpa3 - gpa_mean;
        deviation_gpa4 = gpa4 - gpa_mean;
        deviation_gpa5 = gpa5 - gpa_mean;
        return deviation_gpa1;
        return deviation_gpa2;
        return deviation_gpa3;
        return deviation_gpa4;
        return deviation_gpa5;
    }
    double compute_variance(double deviation_gpa1, double deviation_gpa2, double deviation_gpa3, double deviation_gpa4, double deviation_gpa5, double number) {
        double variance = 0.0;
        number = 5;
        ((deviation_gpa1*deviation_gpa1) + (deviation_gpa2*deviation_gpa2) + (deviation_gpa3*deviation_gpa3) + (deviation_gpa4*deviation_gpa4) + (deviation_gpa5*deviation_gpa5) / number);
        return variance;
    
    
    }
    double compute_standard_deviation(double variance) {
        double standard_d = 0.0;
        standard_d = sqrt(variance);
        return standard_d;
    }
    
    
    
    [MAIN.C FILE]
    compute_deviation = compute_deviation_gpa( gpa1, gpa2,  gpa3,  gpa4,  gpa5, gpa_mean);
    
        compute_variancee = compute_variance(deviation_gpa1, deviation_gpa2, deviation_gpa3, deviation_gpa4, deviation_gpa5, number);
    
    
        compute_sd = compute_standard_deviation(variance);
        
        fprintf(outfile, "sd %.2lf\n ", compute_sd);
        
        return 0;
    whenever i run this, i get zero. I am not sure why.
    Any help is appreciated, thank you.
    this 0 thing look at your second function and third function.

    2nd function
    Code:
     double variance = 0.0;
    return variance;
    a bunch of math between the two but no assigning the results to it,
    3rd function
    Code:
    double compute_standard_deviation(double variance) {
        double standard_d = 0.0;
        standard_d = sqrt(variance);
        return standard_d;
    variance is set to 0.0 how are you getting it into that third function to work on it? I do not see it declared anywhere in your main.

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    
    void compute_deviation_gpa(double * gpa1, double * gpa2, double * gpa3, double * gpa4, double * gpa5, double * gpa_mean)
    
    {
    
    printf("1::IN C DEVATION %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n", *(double*)gpa1, *(double*)gpa2, *(double*)gpa3, *(double*)gpa4, *(double*)gpa5, *(double*)gpa_mean);
    
        *gpa1 = gpa1 - gpa_mean;
        *gpa2 = gpa2 - gpa_mean;
        *gpa3 = gpa3 - gpa_mean;
        *gpa4 = gpa4 - gpa_mean;
        *gpa5 = gpa5 - gpa_mean;
    
    printf("2:: leaving C DEVATION %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n", *(double*)gpa1, *(double*)gpa2, *(double*)gpa3, *(double*)gpa4, *(double*)gpa5, *(double*)gpa_mean);
        
    }
    double compute_variance(double deviation_gpa1, double deviation_gpa2, double deviation_gpa3, double deviation_gpa4, double deviation_gpa5, double number)
    {
        printf("in Compute %f %f %f %f %f %f\n", deviation_gpa1, deviation_gpa2, deviation_gpa3, deviation_gpa4, deviation_gpa5, number);
       
    return( ((deviation_gpa1*deviation_gpa1) + (deviation_gpa2*deviation_gpa2) + (deviation_gpa3*deviation_gpa3) + (deviation_gpa4*deviation_gpa4) + (deviation_gpa5*deviation_gpa5) / number));
    }
    double compute_standard_deviation(double variance) {
    return ( sqrt(variance) );
    }
    
    int main()
    {
    
     double gpa1, gpa2,gpa3,gpa4,gpa5, gpa_mean;
     gpa1 = 5.3;
     gpa2 = 2.3;
     gpa3 = 10.3;
     gpa4 = 123456782.3;
     gpa5 = 2.3;
     gpa_mean = 5.0;
     double number = 5.0;
    double variance, compute_sd;
    
      compute_deviation_gpa( &gpa1, &gpa2, &gpa3, &gpa4, &gpa5,  &gpa_mean);
    
      variance = compute_variance(gpa1, gpa2, gpa3, gpa4, gpa5, number);
    
      compute_sd = compute_standard_deviation(variance);
    
      printf( "sd %.2lf\n ", compute_sd);
    
    // I tried to get it to go one inside other but them end vaules on the two functions were getting in my way
    // printf("sd %f\n ", compute_standard_deviation(compute_variance( compute_deviation_gpa( &gpa1, &gpa2,  &gpa3,  &gpa4, &gpa5, gpa_mean), 5)));
    
    
    return 0;
    }
    results
    Code:
     userx@~/bin <> gcc -Wall  -lm devation_gpa.c
    userx@~/bin <> ./a.out
     1::IN C DEVATION 5.30
     2.30
     10.30
     123456782.30
     2.30
     5.00
    2:: leaving C DEVATION 5.00
     4.00
     3.00
     2.00
     1.00
     5.00
    in Compute 5.000000 4.000000 3.000000 2.000000 1.000000 5.000000
    sd 7.36
    you got a be the judge on the math part. maybe tweak it a bit to suit your needs.

    Pass By Reference
    Last edited by userxbw; 09-24-2017 at 07:13 PM.

  6. #6
    Banned
    Join Date
    Aug 2017
    Posts
    861

    you're going to the power of 2?

    letting MATH.H do most of the work.

    C library function pow()

    this may or may not be right but others in here could gils you better, I'm just raising the point or giving you another means of doing this. the options


    Code:
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    
    double   compute_deviation_gpa(double * gpa1, double * gpa2, double * gpa3, double * gpa4, double * gpa5, double * gpa_mean)
    
    {
    printf("1::IN C DEVATION %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n", *(double*)gpa1, *(double*)gpa2, *(double*)gpa3, *(double*)gpa4, *(double*)gpa5, *(double*)gpa_mean);
    
        *gpa1 = gpa1 - gpa_mean;
        *gpa2 = gpa2 - gpa_mean;
        *gpa3 = gpa3 - gpa_mean;
        *gpa4 = gpa4 - gpa_mean;
        *gpa5 = gpa5 - gpa_mean;
    
    printf("2:: leaving C DEVATION %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n", *(double*)gpa1, *(double*)gpa2, *(double*)gpa3, *(double*)gpa4, *(double*)gpa5, *(double*)gpa_mean);
       return 0.0;
    }
    double compute_variance(double d_gpa1, double d_gpa2, double d_gpa3, double d_gpa4, double d_gpa5)
    {
        printf("in Compute %f %f %f %f %f \n", d_gpa1, d_gpa2, d_gpa3, d_gpa4, d_gpa5);
    
        // no number needed to be passed into function because it only takes five
    
       printf(" do the math: %f \n",  ( ((d_gpa1*d_gpa1) + (d_gpa2*d_gpa2) + (d_gpa3*d_gpa3) + (d_gpa4*d_gpa4) + (d_gpa5*d_gpa5) / 5))  );
    
       // raised to the power of 2 then the total divided by how many to get advarage?
       printf("being returned using pow( ) : %f \n",  (  (pow(d_gpa1, 2) + pow(d_gpa2,2) + pow(d_gpa3, 2) + pow(d_gpa4,2) + pow(d_gpa5, 2) ) / 5 ));
    
    
    // shortened it for readability it was too long
     //  return (  ( ((d_gpa1*d_gpa1) + (d_gpa2*d_gpa2) + (d_gpa3*d_gpa3) + (d_gpa4*d_gpa4) + (d_gpa5*d_gpa5) / 5))  )
    
        return (  (pow(d_gpa1, 2) + pow(d_gpa2,2) + pow(d_gpa3, 2) + pow(d_gpa4,2) + pow(d_gpa5, 2) ) / 5 );
    }
    double compute_standard_deviation(double variance) {
    return ( sqrt(variance) );
    }
    
    int main()
    {
    
     double gpa1, gpa2,gpa3,gpa4,gpa5, gpa_mean;
     gpa1 = 5.3;
     gpa2 = 2.3;
     gpa3 = 10.3;
     gpa4 = 123456782.3;
     gpa5 = 2.3;
     gpa_mean = 7.0;
    double  compute_sd;
    
    //    printf( "sd %.2lf\n ", compute_sd);
    // raised to the power of 2 (deviation3)^2  ???? pow(gpa1,2) ??
    
    
        compute_deviation_gpa( &gpa1, &gpa2, &gpa3, &gpa4, &gpa5,  &gpa_mean);
        compute_sd = compute_standard_deviation(  compute_variance(gpa1, gpa2, gpa3, gpa4, gpa5)  ) ;
        printf( "\n@:  sd %.2lf\n ", compute_sd);
    
    
    
    return 0;
    }
    Code:
    serx@~/bin <> gcc -Wall  -lm devation_gpa.c
    userx@~/bin <> ./a.out
    1::IN C DEVATION 5.30
     2.30
     10.30
     123456782.30
     2.30
     7.00
    2:: leaving C DEVATION 5.00
     4.00
     3.00
     2.00
     1.00
     7.00
    in Compute 5.000000 4.000000 3.000000 2.000000 1.000000 
     do the math: 54.200000 
    being returned using pow( ) : 11.000000 
    
    @:  sd 3.32

  7. #7
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Now it is working using pow() in math.h
    Code:
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    
    double   compute_deviation_gpa(double * gpa1, double * gpa2, double * gpa3, double * gpa4, double * gpa5, double * gpa_mean)
    
    {
    printf("1::IN C DEVATION %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n", *(double*)gpa1, *(double*)gpa2, *(double*)gpa3, *(double*)gpa4, *(double*)gpa5, *(double*)gpa_mean);
    
        *gpa1 = gpa1 - gpa_mean;
        *gpa2 = gpa2 - gpa_mean;
        *gpa3 = gpa3 - gpa_mean;
        *gpa4 = gpa4 - gpa_mean;
        *gpa5 = gpa5 - gpa_mean;
    
    printf("2:: leaving C DEVATION %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n %.2lf\n", *(double*)gpa1, *(double*)gpa2, *(double*)gpa3, *(double*)gpa4, *(double*)gpa5, *(double*)gpa_mean);
       return 0.0;
    }
    double compute_variance(double d_gpa1, double d_gpa2, double d_gpa3, double d_gpa4, double d_gpa5)
    {
        printf("in Compute %f %f %f %f %f \n", d_gpa1, d_gpa2, d_gpa3, d_gpa4, d_gpa5);
        // no number needed to be passed into function because it only takes five
       printf(" do the math old way: %lf \n",  ( ((d_gpa1*d_gpa1) + (d_gpa2*d_gpa2) + (d_gpa3*d_gpa3) + (d_gpa4*d_gpa4) + (d_gpa5*d_gpa5) / 5))  );
       // raised to the power of 2 then the total divided by how many to get advarage?
       printf("being returned using pow( ) : %lf \n", (  (pow(d_gpa1, 2)  ) + ( pow(d_gpa2, 2) ) + ( pow(d_gpa3, 2) ) + ( pow(d_gpa4, 2) ) + ( pow(d_gpa5, 2) ) /  5) );
    
    
    return (  (pow(d_gpa1, 2)  ) + ( pow(d_gpa2, 2) ) + ( pow(d_gpa3, 2) ) + ( pow(d_gpa4, 2) ) + ( pow(d_gpa5, 2) ) /  5);
    }
    double compute_standard_deviation(double variance) {
    return ( sqrt(variance) );
    }
    
    int main()
    {
    
     double gpa1, gpa2,gpa3,gpa4,gpa5, gpa_mean;
     gpa1 = 5.3;
     gpa2 = 2.3;
     gpa3 = 10.3;
     gpa4 = 123456782.3;
     gpa5 = 2.3;
     gpa_mean = 7.0;
    double  compute_sd;
    
        compute_deviation_gpa( &gpa1, &gpa2, &gpa3, &gpa4, &gpa5,  &gpa_mean);
        compute_sd = compute_standard_deviation(  compute_variance(gpa1, gpa2, gpa3, gpa4, gpa5)  ) ;
        printf( "\nAnswer: :  sd %.2lf\n ", compute_sd);
    
    return 0;
    }
    results, ok I hope you get a look at this
    Code:
    userx@~/bin <> ./a.out
    1::IN C DEVATION 5.30
     2.30
     10.30
     123456782.30
     2.30
     7.00
    2:: leaving C DEVATION 5.00
     4.00
     3.00
     2.00
     1.00
     7.00
    in Compute 5.000000 4.000000 3.000000 2.000000 1.000000 
     do the math old way: 54.200000 
    being returned using pow( ) : 54.200000 
    
    Answer: :  sd 7.36

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    you got a be the judge on the math part.
    Okay I will question your "math". In the compute_deviation_gpa() function you show that on entry to the function gpa1 is equal to 5.30 and gpa_mean is 5.00. Yet you report that on leaving the function gpa1 will be equal to 5.00. This "math" doesn't add up since the "math" should be 5.30 - 5.00 which should be .30 not 5.00.

    Can you explain why your modifications are reporting false values?

    Jim

  9. #9
    Banned
    Join Date
    Aug 2017
    Posts
    861
    if you are taling to me and not the OP , I did not mess with his math, I just modied it to return through the pharm as he had it written to return each one seperatly.

    to help you not have to go look at the first post.

    is not this what he wrote:
    finction 1:
    Code:
      deviation_gpa1 = gpa1 - gpa_mean;    deviation_gpa2 = gpa2 - gpa_mean;
        deviation_gpa3 = gpa3 - gpa_mean;
        deviation_gpa4 = gpa4 - gpa_mean;
        deviation_gpa5 = gpa5 - gpa_mean;
    the same as this?
    Code:
        *gpa1 = gpa1 - gpa_mean;
        *gpa2 = gpa2 - gpa_mean;
        *gpa3 = gpa3 - gpa_mean;
        *gpa4 = gpa4 - gpa_mean;
        *gpa5 = gpa5 - gpa_mean;
    it just reassigns the value in the same var.

    I changed this in function2:
    keeping in mind he did not assign the results of this to anything so he was getting zero
    Code:
     ((deviation_gpa1*deviation_gpa1) + (deviation_gpa2*deviation_gpa2) + (deviation_gpa3*deviation_gpa3) + (deviation_gpa4*deviation_gpa4) + (deviation_gpa5*deviation_gpa5) / number);
    to this
    [code]
    return ((deviation_gpa1*deviation_gpa1) + (deviation_gpa2*deviation_gpa2) + (deviation_gpa3*deviation_gpa3) + (deviation_gpa4*deviation_gpa4) + (deviation_gpa5*deviation_gpa5) / number);

    I didn;t change anything, just had that math done in the return.

    function3
    I did the same,
    Code:
    double standard_d = 0.0;    standard_d = sqrt(variance);
        return standard_d;
    to this
    Code:
    return ( sqrt(variance) );
    so I did not set up the math I just fixed it to return the results his math equations.

    then later I looked into what math.h may have to do some of it too. pow(x,y);
    I just shortened the var names so it is not so long making it eaier to fit on one line.
    Code:
    return (  (pow(d_gpa1, 2)  ) + ( pow(d_gpa2, 2) ) + ( pow(d_gpa3, 2) ) + ( pow(d_gpa4, 2) ) + ( pow(d_gpa5, 2) ) /  5);
    again I am not doing the equations nor the math that is done by the PC.

  10. #10
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by jimblumberg View Post
    Okay I will question your "math". In the compute_deviation_gpa() function you show that on entry to the function gpa1 is equal to 5.30 and gpa_mean is 5.00. Yet you report that on leaving the function gpa1 will be equal to 5.00. This "math" doesn't add up since the "math" should be 5.30 - 5.00 which should be .30 not 5.00.

    Can you explain why your modifications are reporting false values?

    Jim
    that is a good question I put printf i the function doing showing this
    Code:
    **/
        printf("values being reasinged to var\n");
        printf(" gpa1 %lf\n", *(double*)gpa1);
        printf("gpa-mean %lf\n", *(double*)gpa_mean);
        printf("  *gpa1 = gpa1 - gpa_mean --> %lf\n",  ( *(double*)gpa1 = gpa1 - gpa_mean) );
    Code:
    this
    deviation_gpa1 = gpa1 - gpa_mean;
    should be the same as this
     *gpa1 = gpa1 - gpa_mean;
    yes?
    results
    Code:
    values being reasinged to var
     gpa1 5.300000
    gpa-mean 5.000000
      *gpa1 = gpa1 - gpa_mean --> 5.000000
    I did not mess with the equations.

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I did not mess with the equations.
    That's good because it's not the equations that are the problem.

    Look at this snippet
    Code:
     printf(" gpa1 %lf\n", *(double*)gpa1);
    This is small part of your problem. Can you explain the purpose of the cast?

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why so wrong numbers? As I write so wrong?
    By Dmy in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2017, 02:10 PM
  2. Replies: 3
    Last Post: 11-14-2011, 06:35 PM
  3. wrong wrong with my xor function?
    By Anddos in forum C++ Programming
    Replies: 5
    Last Post: 04-26-2009, 01:38 PM
  4. whats wrong with this? no errors but wrong result
    By InvariantLoop in forum C Programming
    Replies: 6
    Last Post: 01-28-2005, 12:48 AM
  5. Replies: 9
    Last Post: 07-15-2004, 03:30 PM

Tags for this Thread