#include <iostream>
using namespace std;
void BMI(double height, double weight);
int main()
{
double feet; // to store in feet
double inches;
double pounds;
double meters;
double kg;
const double KILOGRAMS = 2.2;
const double FEET_METER = 0.0254;
cout << "Enter your height in feet and then inches: " << endl;
cout << "Feet: "
cin >> feet;
cout << "Inches: "
cin >> inches;
cout << "Enter your weight in pounds: "
cin >> pounds;
inches = inches + (feet*12);
meters = inches * FEET_METER;
kg = pounds / KILOGRAMS;
void BMI (double meters, double kg);
return 0;
}
void BMI(double height, double weight)
{
double bmi;
bmi = weight / (height^2)
cout << "Your BMI is " << BMI;
}
BMI code help
Page 1 of 14 Replies - 536 Views - Last Post: 24 February 2012 - 10:48 AM
#1
BMI code help
Posted 24 February 2012 - 10:37 AM
I am using the primer plus (5th edition) book and in one of the programming examples it asks you to calculate the body mass index. My compiler (visual c++ and net beans both) shows an error. I was wondering if anyone could helps. Thanks in advance
Replies To: BMI code help
#2
Re: BMI code help
Posted 24 February 2012 - 10:38 AM
And the error is . . . ?
Edit:
On looking through your code I saw that the way you are calling your function is wrong
Edit:
On looking through your code I saw that the way you are calling your function is wrong
void doSomething(int a); // this is a function declaration
doSomething(5); // this is a function call. Note the lack of 'void' and 'int'
// and other typenames :)/>
int p = 3;
doSomething(p);
This post has been edited by sk1v3r: 24 February 2012 - 10:44 AM
#3
Re: BMI code help
Posted 24 February 2012 - 10:44 AM
This is a function declaration:
This is a function call:
Inside your main, you want to call the function, not declare it.
void BMI (double meters, double kg);
This is a function call:
BMI(meters, kg);
Inside your main, you want to call the function, not declare it.
#4
Re: BMI code help
Posted 24 February 2012 - 10:44 AM
On line 32 you wrote the function call exactly like the function prototype. The call should just be:
BMI (meters,kg);
#5
Re: BMI code help
Posted 24 February 2012 - 10:48 AM
Of course how silly of me thanks for the help
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|