• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to apply casting correctly for heightProgram?  RSS feed

 
Ricardo Arteaga
Greenhorn
Posts: 16
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to figure how to calculate the child's height in float value but i dont know if im
doing it correctly and been trying to figure it out and stuck on it?
Also need help fixing value where if you choose male the accurate value, but
if you choose female the value will be accurate too.

based on http://www.calculator.net/height-calculator.html


 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to retain the fractional part in a division you need to make your numberic literals floating point values.
At the moment they are integers and dividing an int by an int will give you an int. So 12 / 13 is 0 and 13 / 12 is 1.
Try changing the literals to 12.0, 13.0 and 2.0 and se if that helps.

And just as an FYI, don't use == true or != true in boolean comparisons. It's prone to error - it's very easy to type = instead of ==.
Just use
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better not to use those Strings; use an enumerated type with MALE and FEMALE as elements.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!