Help with makefiles!

This is a discussion on Help with makefiles! within the C Programming forums, part of the General Programming Boards category; Here's my files: 1.c Code: #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> int xPosMatterCalc(int sigmaMatter, int muMatter, float xRand) ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    42

    Help with makefiles!

    Here's my files:

    1.c
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    
    int xPosMatterCalc(int sigmaMatter, int muMatter, float xRand)
    {
        int xPosMatter = 1/(sigmaMatter*2.506627216)*exp(-((xRand-muMatter)*(xRand-muMatter))/(2*(sigmaMatter*sigmaMatter)));
        return xPosMatter;
    }
    2.c
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    
    int xPosAntiMatterCalc(int sigmaAntimatter, int muAntimatter, float xRand)
    {
        float xPosAntimatter = 1/(sigmaAntimatter*2.506627216)*exp(-pow((xRand-muAntimatter), 2)/(2*(pow(sigmaAntimatter, 2))));
        return xPosAntimatter;
    }
    3.c
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    #include "hw2-paulomans-1.h"
    #include "hw2-paulomans-2.h"
    
    int main(void)
    {
        int sigmaMatter = 4.2;
        int muMatter = 27.0;
        int sigmaAntimatter = 6.0;
        int muAntimatter = 17.0;
        int xRand = 0.0;
        int seed = time(NULL);
        srand(seed);
        xRand = rand() % 36;
        xPosMatterCalc(sigmaMatter, muMatter, xRand);
        xPosAntiMatterCalc(sigmaAntimatter, muAntimatter, xRand);
        float xProbability = xPosMatter * xPosAntimatter;
        int i;
        float count = 0.0; 
        float p = 0.0;
        float pTotal = 0.0;
        for(i =0; i <= 4999; i=i+1)
        {
            p = 0.09498629735*exp(-((27-xRand)*(27-xRand))/25.28)*0.06649040814*exp(-((17-xRand)*(17-xRand))/72);
            count++;
            pTotal = pTotal + p;
        }
        float pFinal = pTotal/count;
        printf("\nSigma Matter: %d\nSigma Anti-matter: %d\nMu Matter: %d\nMu Anti-matter: %d", sigmaMatter, sigmaAntimatter, muMatter, muAntimatter);
        printf("\nTotal iterations: %d", count);
        printf("\nFinal probability: %d\n", pFinal);
    }
    1.h
    Code:
    int xPosMatterCalc(int sigmaMatter, int muMatter, float xRand);
    2.h
    Code:
    int xPosAntiMatterCalc(int sigmaAntimatter, int muAntimatter, float xRand);
    makefile
    Code:
    hw2make: hw2-paulomans-1.c hw2-paulomans-2.c hw2-paulomans-3.c
        gcc -o hw2-paulomans hw2-paulomans-1.c hw2-paulomans-2.c hw2-paulomans-3.c -I.
    When I try to execute the makefile, it gives me this error:
    Code:
    3.c: In function ‘main’:
    3.c:20:23: error: ‘xPosMatter’ undeclared (first use in this function)
    3.c:20:23: note: each undeclared identifier is reported only once for each function it appears in
    3.c:20:36: error: ‘xPosAntimatter’ undeclared (first use in this function)
    Can someone help me out?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,676
    Not a make file issue, you use xPosMatter and xPosAntimatter in 3.c, but never define it in a scope visible in your main funciton.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    42
    Well, that was a really silly problem, xPosMatter and xPosAntiMatter were the old variable names. I changed them to xPosMatterCalc and xPosAntiMatterCalc and now I'm getting a different error:
    Code:
    3.c: In function 'main':
    3.c:20: error: invalid operands to binary * (have 'int (*)(int, int, float)' and 'int (*)(int, int, float)')
    I'll continue bumming around with it, I probably just forgot to change a variable type somewhere.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,854
    You seem to be confusing function names with variable names.

    And the belief that a variable name within a function automatically creates the same variable name in the caller.

    Try this.
    Code:
    int result1 = xPosMatterCalc(sigmaMatter, muMatter, xRand);
    int result2 =xPosAntiMatterCalc(sigmaAntimatter, muAntimatter, xRand);
    float xProbability = result1 * result2; // NOT xPosMatter * xPosAntimatter which are variables INSIDE the functions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    42
    Quote Originally Posted by Salem View Post
    You seem to be confusing function names with variable names.

    And the belief that a variable name within a function automatically creates the same variable name in the caller.

    Try this.
    Code:
    int result1 = xPosMatterCalc(sigmaMatter, muMatter, xRand);
    int result2 =xPosAntiMatterCalc(sigmaAntimatter, muAntimatter, xRand);
    float xProbability = result1 * result2; // NOT xPosMatter * xPosAntimatter which are variables INSIDE the functions.
    I got it working! Thanks for the helpful info. I ended up using doubles instead of floats and for some reason that corrected the output.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefiles depending on other makefiles
    By _Mike in forum Tech Board
    Replies: 3
    Last Post: 09-02-2011, 11:25 PM
  2. Makefiles!
    By AmbliKai in forum C Programming
    Replies: 6
    Last Post: 11-29-2007, 02:36 AM
  3. Makefiles
    By DaveHope in forum C Programming
    Replies: 1
    Last Post: 10-06-2005, 01:42 AM
  4. makefiles
    By bto19 in forum C++ Programming
    Replies: 1
    Last Post: 12-12-2003, 01:33 PM
  5. Makefiles
    By Jez_Master in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2002, 10:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21