Ask coding questions

← Back to all posts
how do I name a value that is from two outputs
DEA7HREAPER11 (0)

The code I have has an end goal of calculating BMI based on the inputs of the user. The two inputs are inches and pounds, which are converted to cm and kg(metric). The BMI is calculated by (mass in kg)/(height in m)^2. Everything works and BMI is calculated perfectly, my question is how do I label this final output as BMI so I can add additional if statements based on the BMI value?

I figured out how to get my BMI. And thanks for the suggestion malvoliothegood, was wondering why my ^2 wasnt working at first .

Answered by malvoliothegood (147) [earned 5 cycles]
View Answer
Commentshotnewtop
malvoliothegood (147)
  • You can use the cmath library pow function to square a number. Include the cmath library at the top of your code #include <cmath>
  • Declare a variable to store the BMI at the top of main: float BMI;
  • Here is what your code could look like:
  //Evaluating BMI
  BMI = (WeightPound / 2.20462) / pow(((HeightInch*2.540) / 100), 2);
  cout << "\nYour calculated BMI rating is: " << BMI <<endl;
KelvinVerhey (18)

Never understood why they chose to make the ^ in C-like languages bitwise OR. Since nearly every other language it's to the power of. Oh well...