4 Replies - 536 Views - Last Post: 24 February 2012 - 10:48 AM Rate Topic: -----

#1 hmajid2301  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 4888
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#4 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1831
  • View blog
  • 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);

Was This Post Helpful? 0
  • +
  • -

#5 hmajid2301  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1