Function calling with multiple parameters

Trying trying to figure out how I would call this bmi function under the MAIN.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//BMI Calculator using function with return variable
//Created by Ashish Mishra
//Oct 2nd, 2011

#include<iostream>
#include<iomanip>
#include<math.h> // avoid cmath due to ambugious error

float bmi(float weight, float height){
      float bmi = (weight/pow(height,2))*703;
      return bmi;
}   

using namespace std;

int main()
{
    float weight;
    float height;
    float bmi;
    
    cout<<"Please enter your weight (lbs): ";
    cin>>weight;
    cout<<"Please enter your height (inches): ";
    cin>>height;
    
    cout<<fixed<<showpoint<<setprecision(2);
    cout<<"Your BMI is "<<bmi<<endl;
 
    system("pause");
return 0;
}


Is it necessary to re-declare the variable bmi under main?
As you notice, there's no function prototype at this time, I was running test to see if the function works.

Hello,

bmi isn't a variable in your main() so it shouldn't be declared as a float.

To make the code work as it stands you need to pass the parameters to your bmi function

eg

cout<<"Your BMI is "<< bmi(weight, height)<<endl;

If you did want to use a variable it would be done something like this:

1
2
3
4
5
6
float MyBmi

...
MyBmi = bmi(weight, height);
 cout<<"Your BMI is "<<MyBmi<<endl;
...
That helps! Thank you!
Topic archived. No new replies allowed.