File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with variable

 
Dominic Griffin
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to calculate occupancy the occupancy rate of an hotel. The expression is returning a zero. Does anyone see an obvious solution?


 
Henry Wong
author
Marshal
Pie
Posts: 20823
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variables on the right are ints, so when you do the division, it will truncate the non-integer portion. The variable that you are assigning to is also an int, and hence, can't hold the non-integer portion.

It may be a good idea to cast to floating point before doing the division -- and assign it to a floating point variable.

Henry
 
Fred Hamilton
Ranch Hand
Posts: 684
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In other words, your program has only two possibilities. Hotel is full, or hotel is empty.
 
Dominic Griffin
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The lightbulb just clicked. It all makes sense now. Thank you gentlemen!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic