Thread: Help Again!!

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    15

    Help Again!!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    
    void getInput(int *pinFeet, 
                  double *pinInches,
                  int *pinAge,
                  double *pinWeight);
    void doCalculations(double *pinchesDone,  
                        double *pcentimetersDone, 
                        double *pmetersDone,
                        double *pBMIdone,
                        double *pBMRdone,
                        int feet, 
                        double inches,
                        double calcKilo,
                        double meterDone,
                        double centimeterDone);
    void printOutput(double BMIdone, 
                     double BMRdone);
    double calcKilo(double weight);
    double calcBMI(double calcKilo, 
                   double meterCalc);
    double calcBMR(double calcKilo,
                   double centimeterCalc,
                   int age);
    double inchesCalc(int feet,
                      double inches);
    double centimeterCalc(int feet,
                          double inches);
    double meterCalc(int feet, 
                     double inches);
    
    
    int main()
    {
    	int inFeet;        
        double inInches;  
        int inAge;
        double inWeight;
    	double inchesDone;     
    	double centimetersDone;
    	double metersDone;     
    	double BMIdone;
    	double BMRdone;
    	int pfeet;              
    	double pinches;        
    
    	getInput(&inFeet, &inInches, &inAge, &inWeight); 
    	doCalculations(&inchesDone, &centimetersDone, &metersDone, &BMIdone, &BMRdone, inFeet, inInches, inWeight, inAge, calcKilo, centimetersDone, metersDone);
    	printOutput(BMIdone, BMRdone);
    	system("pause");
    	return 0;
    } 
    
    
    void getInput(int *pfeet,
    			  double *pinches,
                  int *page,
                  double *pweight)
    {
    	printf("Enter  Height in Feet & Inches: "); 
    	scanf("%lf %lf", pfeet, pinches);
        printf("Enter weight in pounds: ");
        scanf("%lf", page);
        printf("Enter age in years (whole # only): ");
        scanf("%lf", pweight); 
    }/
    
    
    void doCalculations(double *pinchesDone,
    			        double *pcentimetersDone,
                        double *pmetersDone,
                        double *pBMIdone,
                        double *pBMRdone,
    			        int feet,
    			        int age,
    			        double inches,
                        double calcKilo,
    					double meterDone,
    					double centimeterDone)
    {
    
    
    	*pinchesDone = inchesCalc(feet, inches); 
    	*pcentimetersDone = centimeterCalc(feet, inches); 
    	*pmetersDone = meterCalc (feet, inches); 
    	*pBMIdone = calcBMI (calcKilo, meterDone);
        *pBMRdone = calcBMR (calcKilo, centimeterDone, age);
    }
    
    
    void printOutput(double BMIdone,
    			     double BMRdone)
    {
    // Statements                 
    	printf("The BMI = %.3f\n", BMIdone); 
    	printf("The BMR = %.3f\n", BMRdone); 
    }
    
    double calcBMI (double calcKilo, double meterCalc)
    {
        return calcKilo / (meterCalc * meterCalc);
    }
    
    double CalcBMR (double calcKilo, double centimeterCalc, int age)
    {
       return 66 + (13.75 * calcKilo) + (5 * centimeterCalc) - (6.8 * age);
    }
    
    double calcKilo (double weight)
    {
        int kiloFin;
        int kiloRem;
        
        kiloFin = weight / 2.2;
        kiloRem = fmod(kiloFin, 2.2);
        return kiloFin + kiloRem;
    }
    
    
    double inchesCalc(int feet,
    				  double inches)
    {
    
         int feetToInch; 
         
         feetToInch = feet * 12;
    	return feetToInch + inches; 
    }
    
    
    double centimeterCalc(int feet, 
                          double inches)
    {
                         
    	int feetToInch2; 
    
    	feetToInch2 = feet * 12; 
    	return (feetToInch2 + inches) * 2.54;  2.54 to give centimeters
    }
    
    double meterCalc(int feet,      
                     double inches)
    {
                   
        int feetToInch3; 
        double inchToCent;
        
        feetToInch3 = feet * 12; 
        inchToCent = (feetToInch3 + inches) * 2.54; 
        return inchToCent / 100;  meters
    }
    Its suppose to calculate BMI, and BMR. I took the script i posted earlier for unite conversion and just added to it. What is going wrong?

  2. #2
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    YOu are not not giving enough info

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Your BMI function (for instance) uses calcKilo and meterDone, but you never bother putting any numbers in those variables.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    So it usually helps if you ask more specific questions, like "why do I get an error about parameter 10 in doCalculations" (answer: prototype, definition and call are all different)? My compiler threw up all over when it saw your code, so fix these first:
    $ gcc -Wall body.c
    body.c: In function ‘main’:
    body.c:51: error: incompatible type for argument 10 of ‘doCalculations’
    body.c:10: note: expected ‘double’ but argument is of type ‘double (*)(double)’
    body.c:51: error: too many arguments to function ‘doCalculations’
    body.c:48: warning: unused variable ‘pinches’
    body.c:47: warning: unused variable ‘pfeet’
    body.c: In function ‘getInput’:
    body.c:64: warning: format ‘%lf’ expects type ‘double *’, but argument 2 has type ‘int *’
    body.c:66: warning: format ‘%lf’ expects type ‘double *’, but argument 2 has type ‘int *’
    body.c: At top level:
    body.c:69: error: expected identifier or ‘(’ before ‘/’ token
    body.c: In function ‘centimeterCalc’:
    body.c:141: warning: statement with no effect
    body.c:141: error: expected ‘;’ before ‘to’
    body.c: In function ‘meterCalc’:
    body.c:153: error: ‘meters’ undeclared (first use in this function)
    body.c:153: error: (Each undeclared identifier is reported only once
    body.c:153: error: for each function it appears in.)
    body.c:154: error: expected ‘;’ before ‘}’ token

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    15
    so would i just add
    Code:
    calcKilo = calcKilo
    meterDone = meterDone
    in the doCalculations?

    I thought that my functions were taking care of those calculations.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by Jjoraisnt32 View Post
    so would i just add
    Code:
    calcKilo = calcKilo
    meterDone = meterDone
    in the doCalculations?

    I thought that my functions were taking care of those calculations.
    Saying meterDone = meterDone just copies the current value on top of itself, basically having no effect. You do initialize meterDone, albeit in a very confusing way (passing the value and address into doCalculations), but the copy of meterDone that you pass to calcBMI comes from the uninitialized variable in main (passed in by value), and doesn't reflect the result of meterCalc().

    Also, calcKilo is a function, so you can't pass it into function that expects a plain old double.

  7. #7
    Registered User
    Join Date
    Feb 2011
    Posts
    15
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    
    void getInput(int *pinFeet, 
                  double *pinInches,
                  int *pinAge2,
                  double *pinWeight);
    void doCalculations(double *pinchesDone,  
                        double *pcentimetersDone, 
                        double *pmetersDone,
    					double *pcalcKiloDone,
                        double *pbmiDone,
                        double *pbmrDone,
                        int feet, 
                        double inches,
    					double weight,
    					int age2,
                        double calcKilo,
                        double meterDone,
                        double centimeterDone);
    void printOutput(double bmiDone, 
                     double bmrDone);
    double calcKilo(double weight);
    double calcBMI(double calcKilo, 
                   double meterCalc);
    double calcBMR(double calcKilo,
                   double centimeterCalc,
                   int age2);
    double inchesCalc(int feet,
                      double inches);
    double centimeterCalc(double inchesDone2);
    double meterCalc(double inchesDone2);
    
    
    int main()
    {
    	int inFeet;      
        double inInches;
        int inAge2;
        double inWeight;
    	double inchesDone; 
    	double centimetersDone; 
    	double metersDone;     
    	double calcKiloDone;
    	double inchesDone2;
    	double bmiDone;
    	double bmrDone;
    	int page2;
    	int pfeet;           
    	double pinches;
    	double pweight;
    	double calcKilo2;
    	double centimeterCalc2;
    	double meterCalc2;
    
    	getInput(&inFeet, &inInches, &inAge2, &inWeight); 
    	doCalculations(&inchesDone, &centimetersDone, &metersDone, &bmiDone, &calcKiloDone, &bmrDone, inFeet, inInches, inWeight, inAge2);
    	printOutput(bmiDone, bmrDone); 
    	system("pause");
    	return 0;
    }
    
    
    void getInput(int *pfeet,
    			  double *pinches,
                  int *page2,
                  double *pweight)
    {
    	printf("Enter  Height in Feet & Inches: ");
    	scanf("%lf %lf", pfeet, pinches);
        printf("Enter weight in pounds: ");
        scanf("%lf", page2);
        printf("Enter age in years (whole # only): ");
        scanf("%lf", pweight); 
    }
    
    
    void doCalculations(double *pinchesDone,
    			        double *pcentimetersDone,
                        double *pmetersDone,
    					double *pcalcKiloDone,
                        double *pbmiDone,
                        double *pbmrDone,
    			        int feet,
    			        int age2,
    			        double inches,
    					double weight,
    					double calcKilo2,
    					double meterCalc2,
    					double inchesDone2,
    					double centimeterCalc2)
    {
    	*pinchesDone = inchesCalc(feet, inches);
    	*pcalcKiloDone = calcKilo(weight);
    	calcKilo2 = *pcalcKiloDone;
    	inchesDone2 = *pinchesDone;
    	centimeterCalc2 = *pcentimetersDone;
    	meterCalc2 = *pmetersDone;
    	*pcentimetersDone = centimeterCalc(inchesDone2); 
    	*pmetersDone = meterCalc (inchesDone2);
    	*pbmiDone = calcBMI (calcKilo2, meterCalc2);
        *pbmrDone = calcBMR (calcKilo2, centimeterCalc2, age2);
    }
    
    
    
    void printOutput(double bmiDone,
    			     double bmrDone)
    {
                    
    	printf("The BMI = %.3f\n", bmiDone); 
    	printf("The BMR = %.3f\n", bmrDone); 
    }
    
    double calcBMI (double calcKilo2, double meterCalc2)
    {
        return calcKilo2 / (meterCalc2 * meterCalc2);
    }
    
    double CalcBMR (double calcKilo2, double centimeterCalc2, int age2)
    {
       return 66 + (13.75 * 2) + (5 * centimeterCalc2) - (6.8 * age2);
    }
    
    double calcKilo (double weight)
    {
        int kiloFin;
        int kiloRem;
        
        kiloFin = weight / 2.2;
        kiloRem = fmod(kiloFin, 2.2);
        return kiloFin + kiloRem;
    }
    
    
    double inchesCalc(int feet,
    				  double inches)
    {
    
         int feetToInch;
         
         feetToInch = feet * 12; 
    	return feetToInch + inches;
    }
    
    
    double centimeterCalc(double inchesDone2)
    {
                        
    
    	return inchesDone2 * 2.54;
    }
    
    
    double meterCalc(double inchesDone2)
    {
                    
        double inchToCent;
        
        inchToCent = inchesDone2 * 2.54;
        return inchToCent / 100; 
    }
    I think i fixed most of it so everything points and calls how it is supposed to. But i get an error that says too few arguments for call in doCalculations. Why??

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Because you called doCalculations with too few arguments. I already told you in post #4, your prototype, definition and call all need to match.

Popular pages Recent additions subscribe to a feed