# BMI code help

Page 1 of 1

## 4 Replies - 536 Views - Last Post: 24 February 2012 - 10:48 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=268075&amp;s=07f1c6d35f17e7e95faac2997180f6f9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hmajid2301

Reputation: 0
• Posts: 9
• Joined: 04-February 12

# 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
```#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;
}

```

Is This A Good Question/Topic? 0

## Replies To: BMI code help

### #2 sk1v3r

Reputation: 231
• Posts: 668
• Joined: 06-December 10

## 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
```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 baavgai

• Dreaming Coder

Reputation: 4888
• Posts: 11,282
• Joined: 16-October 07

## Re: BMI code help

Posted 24 February 2012 - 10:44 AM

This is a function declaration:
```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 r.stiltskin

• D.I.C Lover

Reputation: 1831
• Posts: 4,927
• Joined: 27-December 05

## 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 hmajid2301

Reputation: 0
• Posts: 9
• Joined: 04-February 12

## Re: BMI code help

Posted 24 February 2012 - 10:48 AM

Of course how silly of me thanks for the help