Re: Look Over Code Please!
If you want to get a floating-point result from a calculation involving integral types (e.g. the calculation that gives zero), you need to cast one of the elements involved to a floating-point type, otherwise the result will be an integer (zero) that is assigned to your floating-point variable (an expression is evaluated according to the types in the expression, not the type it gets assigned to). A simple way to do this is either to give one of the numeric literals a decimal point, making it a floating-point literal, or to put an 'f' or 'F' or 'D' or 'd' after it, making it a float or a double respectively, e.g:
intBulbUse = ((intUserBulbs * 16.0) / 1000);
or
intBulbUse = ((intUserBulbs * 16f) / 1000);
A teacher who doesn't know this isn't really a Java teacher... but there are many things to know and learn, and even a teacher can't know eveything.
The generation of random numbers is too important to be left to chance...
R. Coveyou
Re: Look Over Code Please!
Quote:
Originally Posted by
dlorde
If you want to get a floating-point result from a calculation involving integral types (e.g. the calculation that gives zero), you need to cast one of the elements involved to a floating-point type, otherwise the result will be an integer (zero) that is assigned to your floating-point variable (an expression is evaluated according to the types in the expression, not the type it gets assigned to). A simple way to do this is either to give one of the numeric literals a decimal point, making it a floating-point literal, or to put an 'f' or 'F' or 'D' or 'd' after it, making it a float or a double respectively, e.g:
intBulbUse = ((intUserBulbs * 16.0) / 1000);
or
intBulbUse = ((intUserBulbs * 16f) / 1000);
A teacher who doesn't know this isn't really a Java teacher... but there are many things to know and learn, and even a teacher can't know eveything.
The generation of random numbers is too important to be left to chance...
R. Coveyou
Awesome! I really appreciate the quick response!
And your right, my teacher isn't a java teacher. My college used to teach VB up until this semester and my teacher was required to learn the new material, or find another job.