Help!

This is a discussion on Help! within the C Programming forums, part of the General Programming Boards category; I can't figure out how to write the cal function. Code: #include <stdio.h> void getInput(int* pNum1, int* pNum2); void calc(int ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    61

    Help!

    I can't figure out how to write the cal function.
    Code:
    #include <stdio.h>
    
    void getInput(int* pNum1, int* pNum2);
    void calc(int num1, int num2, int* pSum, int* pQuotient, int* pRemainder,
    double* pHalfNum1, double* pHalfNum2, double* pFraction, int* pAlgebra);
    int intOps(int num1, int num2, int* pSum, int* pQuotient, int* pRemainder,
    int* pAlgebra);
    double doubleOps(int num1, int num2, double* pHalfNum1, double* pHalfNum2,
    double* fraction);
    void display(int num1, int num2, int sum, int quotient, int remainder,
    double halfNum1, double halfNum2, double fraction, int algebra);
    
    
    int main(void)
    {
       int num1, num2;
       int sum, quotient, remainder;
       double halfNum1, halfNum2, fraction;
       int algebra;
    
    
       getInput(&num1, &num2);
       calc(num1, num2, &sum, &quotient, &remainder, &halfNum1, &halfNum2,
       &fraction, &algebra);
    
    
       return 0;
    }
    
    
    void getInput(int* pNum1, int* pNum2)
    {
       printf("\nName: Danielle Evans");
       printf("\nPlease enter two integers : ");
       scanf("%d%d", pNum1, pNum2);
    }
    
    
    void calc(int num1, int num2, int* pSum, int* pQuotient, int* pRemainder,
    double* pHalfNum1, double* pHalfNum2, double* pFraction, int* pAlgebra)
    {
       
    }  
    int intOps(int num1, int num2, int* pSum, int* pQuotient, int* pRemainder,
    int* pAlgebra)
    {
       *pSum = num1 + num2;
       *pQuotient = num1 / num2;
       *pRemainder = num1 % num2;
       *pAlgebra = 2 * num1 + 4 * num2 + num1 * num2 - num1 / num2;
    }
    
    
    double doubleOps(int num1, int num2, double* pHalfNum1, double* pHalfNum2,
    double* pFraction)
    {
       *pHalfNum1 = num1 / 2.0;
       *pHalfNum2 = num2 / 2.0;
       *pFraction = num1 / (double)num2;
    }
    
    
    void display(int num1, int num2, int sum, int quotient, int remainder,
    double halfNum1, double halfNum2, double fraction, int algebra)
    {
       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.1lf", "Half of input 1", halfNum1);
       printf("\n%20s%20.1lf", "Half of input 2", halfNum2);
       printf("\n%20s%20d", "Quotient", quotient);
       printf("\n%20s%20d", "Remainder", remainder);
       printf("\n%20s%20.4lf", "Fraction", fraction);
       printf("\n%20s%20d", "Algebra", algebra);
       printf("\n\n");
    }

    This program is somewhat overmodularized but is an exercise in the differentways to pass data throughout functions in a program.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Stop making new threads. You have three going now.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    61
    thanks

Popular pages Recent additions subscribe to a feed

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