- #1
exitwound
- 292
- 1
This is our very first assignment in C++, from the very first week of class so we don't know a whole lot yet. Keep that in mind.
Write a program that will:
-input someone's height in feet and inches
-output that person's height in centimeters
-output the weight in kilograms and pounds for a BMI of 18.5
-output the weight in kilograms and pounds for a BMI of 25.0
BONUS (5 points)
Include exactly one decimal places in all metric outputs and no decimal places on the values in pounds.
The program is done and finished. However, I'm having a little trouble with the bonus question.
We're talking about weights here, so precision isn't required beyond maybe 1 decimal point. He specifically asks for the weights in pounds to be without decimal points so I've converted the floating point variable to an integer, which drops the tenths and just displays the whole portion of the number. I get a warning of 'potential loss of data' from the compiler, but I know that.
We were given that 1in=2.54cm and that 1lb=2.2kg in the instructions to the problem. Now, I assume that he wants us to use those numbers intact in the code to calculate the final answer, and then do something to display them with only 1 decimal digit. However, I can't figure out how to do that. From a google search, I know there's a cout.precision but we haven't talked about it in class and it's not in the first 2 chapters of the book so I'm afraid that's beyond what he's referring to using.
Any thoughts?
Homework Statement
Write a program that will:
-input someone's height in feet and inches
-output that person's height in centimeters
-output the weight in kilograms and pounds for a BMI of 18.5
-output the weight in kilograms and pounds for a BMI of 25.0
BONUS (5 points)
Include exactly one decimal places in all metric outputs and no decimal places on the values in pounds.
The Attempt at a Solution
The program is done and finished. However, I'm having a little trouble with the bonus question.
We're talking about weights here, so precision isn't required beyond maybe 1 decimal point. He specifically asks for the weights in pounds to be without decimal points so I've converted the floating point variable to an integer, which drops the tenths and just displays the whole portion of the number. I get a warning of 'potential loss of data' from the compiler, but I know that.
We were given that 1in=2.54cm and that 1lb=2.2kg in the instructions to the problem. Now, I assume that he wants us to use those numbers intact in the code to calculate the final answer, and then do something to display them with only 1 decimal digit. However, I can't figure out how to do that. From a google search, I know there's a cout.precision but we haven't talked about it in class and it's not in the first 2 chapters of the book so I'm afraid that's beyond what he's referring to using.
Any thoughts?