reset password
Author Message
harry_520
Posts: 76
Posted 23:11 Feb 03, 2015 |

How do we add two negative weight values together? For example, for the two -10 pounds 15 ounces values in the two weight files, when I add them together, the sum becomes -18 pounds 2 ounces. Is this correct? Or should I treat negative weight as positive first. After the addition, add the negative sign in front of the pounds value? So should the sum of this become -21 pounds 14 ounces instead?

giraid
Posts: 39
Posted 23:16 Feb 03, 2015 |
It should be -21 lb 14 oz. You convert everything to positive f4 adding and then concert the answer back, or you can convert the ounces to negative b4 adding Edit, on second thought, you cannot convert everything to positive first, what if one of the operant is positive already? I think you have to convert the ounces to negative instead
Last edited by giraid at 23:19 Feb 03, 2015.
jwarren6
Posts: 56
Posted 23:43 Feb 03, 2015 |

Hey Harry,

-10 lbs 15 oz is the same as -9 lbs -1 oz. If you add (-9 lbs -1 oz) + (-9 lbs -1 oz) = (-18 lbs -2 oz). So, I think your program is really trying to come up with this answer.

Personally, if an input is mixed negative and positive, my constructor transforms both pounds and ounces into negative values accordingly. This way it's easier to add and subtract values. Just my two cents.

harry_520
Posts: 76
Posted 23:58 Feb 03, 2015 |

You guys provided me two different answers. I'm confused.

jwarren6
Posts: 56
Posted 00:53 Feb 04, 2015 |

-10 lbs 15 oz = (-9 lbs -16oz) 15 oz = -9 lbs (-16 oz 15 oz) = -9 lbs -1 oz

giraid
Posts: 39
Posted 07:57 Feb 04, 2015 |
According to Keenan, the negative sign in front of the number of pound means the weight is negative value, pounds and ounces. But he did say that he allows different interpretations. It's all depend on which approach you decide to take, I think the most important thing is to be consistent.
jwarren6
Posts: 56
Posted 14:38 Feb 04, 2015 |

I agree, consistency throughout your program is the key.