Body Mass Index

I was wondering if someone can tell me if I did this exercise from C++ primer right. I'm not sure if I did. I tried to follow along with the exercise the best I could, but not being the best at math has left me to not knowing if there is a logical error, sense the program runs fine..

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
#include<iostream>
#include<cmath>

using namespace std;

int main()
{

// int variables for holding user data

int inches;
int feet;
int weight;

// ask for user input

cout << "Please enter your height in feet: ";
cin >> feet;
cout << endl;
cout << "Please enter your height in inches: ";
cin >> feet;
cout << endl;
cout << "Please enter your weight: ";
cin >> weight;

// conversions are done below

int FeetInInches;
double InchesInMeters;
double MassKG;

FeetInInches = (feet / 12) + inches;
InchesInMeters = inches * 0.0254;
MassKG = weight * 2.2;

//calculate body mass
double BMI;

BMI = MassKG / sqrt(InchesInMeters);

// display Body Mass Index

cout << "Your Body Mass Index Is: " << BMI;


return 0;

}
1
2
3
4
5
cout << "Please enter your height in feet: ";
cin >> feet;
cout << endl;
cout << "Please enter your height in inches: ";
cin >> feet;


FeetInInches = (feet / 12) + inches;
So if I am 12 feet tall, how many inches does your equation here come out with?
Last edited on
oops, that should have been multiplied there, I thought something looked a little funny on the output, lol.

thanks man.
wait maybe not, lol, my mathematics are slacken. What am I supposed to do to fix this?
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
#include<iostream>
#include<cmath>

using namespace std;

int main()
{

// int variables for holding user data

int inches;
int feet;
int weight;

// ask for user input

cout << "Please enter your height in feet: ";
cin >> feet;
cout << endl;
cout << "Please enter your height in inches: ";
cin >> inches;//inches here, not feet
cout << endl;
cout << "Please enter your weight: ";//specify lbs?
cin >> weight;

// conversions are done below

int FeetInInches;
double InchesInMeters;
double MassKG;

FeetInInches = (feet * 12) + inches;//As Moschops said
InchesInMeters = FeetInInches * 0.0254;//Convert the whole thing, not just the inches
MassKG = weight * 2.2;

//calculate body mass
double BMI;

BMI = MassKG / sqrt(InchesInMeters);

// display Body Mass Index

cout << "Your Body Mass Index Is: " << BMI;


return 0;

}
ugh math, lol.

Can only get better I guess. I should have done what Moschops pointed out by running a 1 foot converstion test. I'll have to be weary of that when converting in the future to make sure I have the formula right.

Can't believe I did the to meters conversion, and forgot to include the feet in there, lol, that was a waste. haha.
Topic archived. No new replies allowed.