• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

How can divide this properly these?

 
Greenhorn
Posts: 2
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why is the ratedivided variable zero?
K-perny-fot-2019-12-27-20.43.29.png
[Thumbnail for K-perny-fot-2019-12-27-20.43.29.png]
 
Saloon Keeper
Posts: 9565
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your data types are all wrong. Don't just use the smallest data type just because your value will fit in it. The types 'int' and 'double' tend to be the most efficient because they map closer to today's hardware instruction set and require less implicit conversions. So, no 'byte' and no 'float'. There are special circumstances in which these are appropriate, but yours is not one of them.

Dividing an integer will get you into trouble: 1 / 2 is zero, not 0.5 because the result is an integer as well and '2' goes into '1' zero times. For your algorithm you'll probably want to use doubles for most, if not all, of your parameters, in order to preserve the fractional component.
 
Carey Brown
Saloon Keeper
Posts: 9565
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And Welcome to the Ranch.

In the future we would much prefer that you cut and paste all text into a post, rather than posting a screen shot. Also, when you post code, please UseCodeTags (<- link).
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic