Thread: Help with Functions

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    4

    Help with Functions

    I'm trying to make a basic program to calculate the Body Mass Index using with the options of the imperial system and the option of the metric system by using functions. I'm not sure whats wrong with the code. Any advice would be appreciated.

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    double CalcBMI(double HEIGHT, double WEIGHT, char MEASURE)
    {
     int bmi;
    
           if (MEASURE == m)
              bmi = ((WEIGHT/(HEIGHT*HEIGHT)*10000);
           else
              bmi = ((WEIGHT/(HEIGHT*HEIGHT)*703);
    
              return bmi;
    }
    
    
    
    int main()
    {
    
    double height, weight, BMI;
    char measure;
    
    cout << "Enter the measure (imperial = i or metric = m) being used: " << endl;
    cin >> measure;
    cout << "Enter your height (in inches for imperial, in centimetres for metric): " << endl;
    cin >> height;
    cout << "Enter your weight (in pounds for imperial, in kilograms for metric): " << endl;
    cin >> weight;
    
    BMI = CalcBMI(height, weight, measure);
    cout << "Your body mass index is: " << BMI << endl;
    
          system("PAUSE");
          return 0;
    }

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    13
    Almost there:

    Code:
    double CalcBMI(double HEIGHT, double WEIGHT, char MEASURE)
    {
    	double bmi; //you declared bmi as int
    
    	if (MEASURE == 'm') //you are comparing a char
    		bmi = ((WEIGHT/(HEIGHT*HEIGHT))*10000); //missing )
        else
    		bmi = ((WEIGHT/(HEIGHT*HEIGHT))*703);   //missing )
    
        return bmi;
    }
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg." -- Bjarne Stroustrup

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