Body Mass Index class not working

The second constructor is not working for some reason...

Header:
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
#ifndef BMI_H
#define BMI_H

#include <string>
using namespace std;

class BMI
{
public:
  BMI(const string & newName, int newAge,
    double newWeight, double newHeight);
  BMI(const string & newName, double newWeight, double newHeight);
  double getBMI() const;
  string getStatus()const;
  string getName() const;
  int getAge() const;
  double getWeight() const;
  double getHeight()const;

private:
  string name;
  int age;
  double weight;
  double height;
};

#endif 


Class:
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include "BMI.h"
using namespace std;

BMI::BMI(const string &newName, int newAge,
  double newWeight, double newHeight)
{
  name = newName;
  age = newAge;
  weight = newWeight;
  height = newHeight;
}

BMI::BMI(const string &newName, double newWeight, double newHeight)
{
  name = newName;
  age = 20;
  weight = newWeight;
  height = height;
}

double BMI::getBMI() const
{
  const double KILOGRAMS_PER_POUND = 0.45359237;
  const double METERS_PER_INCH = 0.0254;
  double bmi = weight * KILOGRAMS_PER_POUND /
    ((height * METERS_PER_INCH) * (height * METERS_PER_INCH));
  return bmi;
}

string BMI::getStatus() const
{
  double bmi = getBMI();
  if (bmi < 16)
    return "seriously underweight";
  else if (bmi < 18)
    return "underweight";
  else if (bmi < 24)
    return "normal weight";
  else if (bmi < 29)
    return "overweight";
  else if (bmi < 35)
    return "seriously overweight";
  else
    return "gravely overweight";
}

string BMI::getName() const
{
  return name;
}

int BMI::getAge() const
{
  return age;
}

double BMI::getWeight() const
{
  return weight;
}

double BMI::getHeight() const
{
  return height;
}


Main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include "BMI.h"
using namespace std;

int main()
{
  BMI bmi1("John Doe", 18, 145, 70);
  cout << "The BMI for " << bmi1.getName() << " is "
    << bmi1.getBMI() << " " << bmi1.getStatus() << endl;

  BMI bmi2("Peter King", 215, 70);
  cout << "The BMI for " << bmi2.getName() << " is "
    << bmi2.getBMI() << " " + bmi2.getStatus() << endl;

  system("pause");
  return 0;
}


Here is the output:
1
2
3
The BMI for John Doe is 20.8051 normal weight
The BMI for Peter King is -1.#QNAN gravely overweight
Press any key to continue . . .


Not sure why the second is displaying the reference of the memory..any ideas?
1
2
3
4
5
6
7
BMI::BMI(const string &newName, double newWeight, double newHeight)
{
  name = newName;
  age = 20;
  weight = newWeight;
  height = height;//<<==**********????????? This doesn't help
}
Last edited on
Ah...I see. Thank you for your help.
Topic archived. No new replies allowed.