//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;
}
usingnamespace 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.