• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

how to apply casting correctly for heightProgram?

 
Greenhorn
Posts: 16
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79781
382
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Better not to use those Strings; use an enumerated type with MALE and FEMALE as elements.
 
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic