I am having a problem with an equation. The equation is hm=(h+m/60). h and m are both integers. I am declaring hm as a float because the result would be a decimal number. The problem is the print out gives only the value of h. Here is the code;
It uploads ok. If h=9 and m=44 the sum should be 9+0.733 or 9.733. all I am getting is 9.
What is wrong with the coding? This may be a data type problem or something else.
The division will be done first, then the addition, but all the math is done as integers.
44/60 gives a result of 0, which when added to 9 gives a total of 9.
The conversion to floating point is only done after everything in the parenthesis is complete.
Seconds since the beginning of time, 1 JAN 1970 is handled by RTC libraries, some at least, and another library someone will name, I'm sieved out on it right now.
division is higher precedence than + therefore division is done first then +, e.g.
h+(m/60)
also if m is less than 60 the result of the integer division would be 0
therefore make the calculation floating point
hm=h+(m/60.0)
what type is hm (no sign of a declaration in your code fragment) ?
if it is integer any factional component of h+(m/60.0) would be lost, e.g. 6.50 becomes 6
That system is officially known as Unix Time! IIRC Unix was launched at 0!
I used it in the 90's. A log began every line with Unix Time in 8 char HEX. Unix Time was supposed to get an upgrade, it runs out on Jan 19, 2038 because it uses a signed 32-bit value but that does reach back 68 years as well! It's possible they will simply make a 64 bit version to cover seconds past the Sun becoming a Red Giant!
not correct Paul. division and multiplication take priority over + and -. This equation works now. One very simple change. hm=h+m/60.0. If you don't add the zero m/60 is taken as an integer calculation. This makes it a floating point calculation.
hm was earlier declared as a floating point. your suggestion fixes the problem. you don't need the brackets around m/60.0 because division takes precedence over addition.
He put the parenthesis there for e.g. making the point clear.
When that is done in source code it is for making intention clear so nobody gets ideas later on.