Thread: Help W/ Functions!!

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    1

    Exclamation Help W/ Functions!!

    I am attempting to call a calc function from main and then call intOps and floatOps from calc.

    I am not sure where I am wrong but I always get
    proj2.c
    osprey:~/cproj/proj2$ gcc proj2.c
    proj2.c: In function `calc':
    proj2.c:59: warning: passing arg 3 of `intOps' from incompatible pointer type
    proj2.c:59: warning: passing arg 4 of `intOps' from incompatible pointer type
    proj2.c:59: warning: passing arg 5 of `intOps' from incompatible pointer type
    proj2.c:60: warning: passing arg 3 of `floatOps' from incompatible pointer type
    proj2.c:60: warning: passing arg 4 of `floatOps' from incompatible pointer type
    proj2.c:60: warning: passing arg 5 of `floatOps' from incompatible pointer type
    proj2.c:61: parse error before `int'
    osprey:~/cproj/proj2$

    Here is my code:
    Code:
    #include <stdio.h>
    
    /* Prototypes */
    void getInput(int *pNum1, int *pNum2);
    
    void calc(int num1, int num2, int *pSum, int *pDiv, int *pRemain,
              float *pHalfNum1, float *pHalfNum2, float *pFDiv,
              double *pRaiseToPowerVALUE);
    
    void intOps(int num1, int num2,
                int *pSum, int *pDiv, int *pRemain);
    
    void floatOps(int num1, int num2,
                  float *pHalfNum1, float *pHalfNum2, float *pFDiv);
    
    double raiseToPower(int num1, int num2);
    void display(int num1, int num2, int sum, int div, int remain,
                 float halfNum1, float halfNum2, float fdiv,
                 double raiseToPower);
    
    int main(void)
    {
       int num1;
       int num2;
       int sum, div, remain;
       float halfNum1, halfNum2, fDiv;
       double raiseToPowerVALUE;
    
       getInput(&num1, &num2);
       calc(num1, num2, &sum, &div, &remain, &halfNum1, &halfNum2,
          &fDiv, &raiseToPowerVALUE);
       display(num1, num2, sum, div, remain, halfNum1, halfNum2, fDiv,
          raiseToPowerVALUE);
       
       return;
    }
       
    void getInput(int *pNum1, int *pNum2)
    {
       //Get the user's input
       printf("\nPlease enter 2 integers: ");
       scanf("%d%d", pNum1, pNum2);
       
       return;
    }
    void calc(int num1, int num2, int *pSum, int *pDiv, int *pRemain,
              float *pHalfNum1, float *pHalfNum2, float *pFDiv,   
              double *pRaiseToPowerVALUE)
    {
       intOps(num1, num2, &pSum, &pDiv, &pRemain);
       floatOps(num1, num2, &pHalfNum1, &pHalfNum2, &pFDiv);
       *pRaiseToPowerVALUE = raiseToPower(int num1, int num2);
     
       return;   
    }
     
    void intOps(int num1, int num2, int *pSum, int *pDiv, int *pRemain)
    {
       *pSum = num1 + num2;
       *pDiv = num1 / num2;
       *pRemain = num1 % num2;
     
       return;
    }
              
    void floatOps(int num1, int num2,
                  float *pHalfNum1, float *pHalfNum2, float *pFDiv)
    {
       //Cast to float for accurate division
       *pHalfNum1 = (float) num1 / 2;
       *pHalfNum2 = (float) num2 / 2;
       *pFDiv = (float) num1 / (float) num2;
     
       return;
    }
     
    double RaiseToPower(int num1, int num2)
    {
       double myPow;
       
       pow(num1, num2);
       
       return myPow;
    }
       
    void display(int num1, int num2, int sum, int div, int remain, float
    halfNum1, float halfNum2, float fDiv, double raiseToPowerVALUE)
    {
       printf("\nName: Bobby Dooley");
       
       //Display output in rpt format
       printf("\n%20s%20s", "Description", "Data");
       printf("\n%20s%20s", "-----------", "----");
       printf("\n%20s%20d", "Input 1", num1);
       printf("\n%20s%20d", "Input 2", num2);
       printf("\n%20s%20d", "Sum", sum);
       printf("\n%20s%20.1f", "Half of Input 1", halfNum1);
       printf("\n%20s%20.1f", "Half of Input 2", halfNum2);
       printf("\n%20s%20d", "Quotient", div);
       printf("\n%20s%20d", "Remainder", remain);
       printf("\n%20s%20.4f", "Fraction", fDiv);
       //FORMAT THIS FOR A DOUBLE W/ 0 PRECISION
       printf("\n%20s%20.4f", "Power", raiseToPowerVALUE);
       printf("\n");
    
       return;
    }
    THANK YOU!!!

  2. #2
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178
    i think when you use pointers like
    Code:
    int poiner(int *pNUM1)
    {
               pNUM1 = something * something;
    }
    Then in code you have lot int to float convension.
    Why dont you simply dont put
    Code:
    int sum, div, remain;
    to
    Code:
    float sum, div, remain;
    like in void
    Code:
    intOps(int num1, int num2, int *pSum, int *pDiv, int *pRemain)
    {
       pSum = num1 + num2;
       pDiv = num1 / num2;      /* if you want correct answer you should divade float */
       pRemain = num1 % num2;
    }
    pDiv must me float if you want corect answer!
    Sorry for spelling errors, not English!
    xxxrugby: "All Human Race Will Die From My Hand!"
    xxxrugby: "We are all philosophers, when question is about politics!"

  3. #3
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    I believe the problem is that you're forgetting that inside the calc function, pSum is already a pointer to an int. intOps is expecting a pointer to an integer as well, but what you are passing (&pSum) is a reference to a pointer to an int (basically a pointer to a pointer of type int).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM