I a beginner programmer teaching myself, I am trying to write a program to convert weight ;Stones to pounds. I know that
stones *14 = pounds.
But when I add a decimal to stones I get the wrong answer. I know I need to the (stone*14)+ decimal = pounds FOR EG 15.5 STONE TO POUNDS
But I struggling on how to split the 15.5 stones into
(15 * 4)+ 5
HOW do I do it
code snippet.
float Weight_stones ;
cout << "Please enter wieght in Stones " ;
cin >> Weight_stones ;
i am trying to convert st into lbs and oz.
since 1 st = 14lb i need to
So if someone weighs 15st and 5lbs formula is
(15*14) + 5lbs bit
if the user enters 15.5 i cant separate the whole number from the decimal to complete the formula. I have ask the user to enter the 15 st then the lb. I just want them to enter 15.5 and the program separates them automaticall then applies the formula
I'm unfamiliar with these units, but surely you don't write "15.13 st" when you actually mean "15.93 st"?
Just forget about the decimal point and read both parts separately. If you want to keep the decimal point, you can read two integers instead and use ignore() to discard the decimal point. Alternatively, use fmod.
If you want to get what's after the decimal point, try this: decimals = (value - int(value)) * n
where n is ten to the power of the number of decimal places (if you want 1 decimal place, n = 10^1 = 10; if you want 2 decimal places, n = 10^2 = 100).
Hi Athar these units are old english. When someone gets weighed on scales the scales output in stones and lbs.
So i want the user of the program to enter the weight as they get from the scales and then convert it to lbs or what ever they choose.