I created my self a decimal challenge accidentally but can you figure it out.



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

#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>

using std::cout;
using std::cin;
using std::getline;
using std::string;
using std::endl;

//const void SetHeight (int, int);
struct Mass{
double const Get_Ht(double );
double const Get_Wt(double );
	};
/*
Can anyone work this challenge out, 
well as you probably have noticed the decimal point is not correct, 
 I can't tell you where, however you could use std::fixed and::precision
 but I doubt it will help. 
You can't change the layout but you may notice that the decimal point is wrong, 
 I tried .00022 in wieght and it corrected it,
 but pounds was effected, and altering the weight via 2.54 fixes the BMI
 but effects the height.
 The challenge i guess is to have the decimal place positioned in
 their respective positions, 
 how ever a decimal place doesn't bother me as I got rather close. */
int main()
{
   double Height, Weight;
   double GH, GW, GM;
   Mass Bmi;
 	//SetHeight (inch, feet);
   cout << "Please type Height in feet:_";
   //cin >> Height;
   Height = 6.8;
   GH = Bmi.Get_Ht(Height);
   cout << "Please type Weight in pounds:_";
   //cin >> Weight;
   Weight = 205;
   GW = Bmi.Get_Wt(Weight);
   GM = GW/(GH*GH);
   cout << "Your body mass index is:_" <<GM;
     
};

      double const Mass::Get_Ht(double Height){
      double inch = 12.0, feet = 1, tmp = 0.0254;
      double t = (tmp*Height)*(inch/Height )*Height;
      cout << "\b = " <<t<<" meteres tall \n";
      cout<< " ~~"<<endl;
	    return t;
	 	};
	  double const Mass::Get_Wt(double Weight){
	  float lb = 2.22, feet = 1.0;
      double t = (feet / lb) * Weight;
	    cout << "\b = " << t << " kilos \n";
	    cout << " ~~" << endl;
	    return t;
	 	};
Last edited on
Un-needed semicolon at line 47, 55, and 62.

I don't know what "tmp" is for and why you're multiplying things. BMI formula when dealing with Pounds/Feet is this:

703 x weight (lbs) / [height (in)]2

You don't need to try and convert everything to Metric units.

But if you insist:

To convert Pounds to Kilograms simply Multiply the pounds by 0.45359237

To convert Feet to Meters simply Multiply the feet by 0.3048


Multiplying by those numbers is much easier than what you were doing and very accurate with decimal places.
While the code works, it prints every BMI accurately however only if a person who was 6.8 and maybe 200 pounds entered in the numbers the height would result in a decimal place 2 spots right of the zero, and that would be wrong, (2.07, but still not a big deal) and fixing it only results in 2.7, where the pounds conversation is now with out no decimal place.

Temp is temporary until the number serves a purpose.

I have seen those formulas before online, I can't say they helped finding how a BMI works because of the notation it's written in,

But the numbers you provided do work rather well, just not sure why.
Last edited on
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



#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>

using std::cout;
using std::cin;
using std::getline;
using std::string;
using std::endl;

//const void SetHeight (int, int);
struct Mass{
double const Get_Ht(double );
double const Get_Wt(double );
	};
int main()
{
   double Height, Weight;
   double GH, GW, GM;
   Mass Bmi;
 
   cout << "Please type Height in feet:_";
   //cin >> Height;
   Height = 6.8;
   GH = Bmi.Get_Ht(Height);
   cout << "Please type Weight in pounds:_";
   //cin >> Weight;
   Weight = 205;
   GW = Bmi.Get_Wt(Weight);
   GM = GW/(GH*GH);
   cout << "Your body mass index is:_" <<GM;
     
}

      double const Mass::Get_Ht(double Height){
      double  metres = 0.3048;
      double t = (metres*Height);
      cout << "\b = " <<t<<" meteres tall \n";
      cout<< " ~~"<<endl;
	    return t;

	 	}
      double const Mass::Get_Wt(double Weight){
      double lb  = 0.45359237;
      double t = (lb * Weight);
	  cout << "\b = " << t << " kilos \n";
	  cout << " ~~" << endl;

	    return t;
	 	}
Last edited on
Your original code didn't convert pounds to kilograms correctly.

You fixed the errors before I posted, good work.

Honestly, I looked at your first code and my brain shutdown. It wasn't what I'd do and it looked slightly overly complicated so I couldn't even motivate myself to really look at it to see the issue.

Glad the numbers I provided worked out better.
All I know is the code above works, so does the bottom one. The problem only reveals its self when you apply 6.8 inches, and 205 pounds, type anything else and it works. 21.6 BMI, 207.ect, 93kg converted but fails to place a decimal between 2.07ect.

Both yield the same output, if you type in 5.8inches and 190 pounds both have the decimal positions, not really sure why.

Top code now converts pounds to kilos correctly (92kg)with extra decimal places, but still has the decimal place 207.2423 when complied, just curious why.

Last edited on
Topic archived. No new replies allowed.