We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Most programing languages do not like when variable types mix with eachother. An integer divided by an integer produces a floating point in most cases, but the computer only works with variables that all have the same data type; such as a double divided by a double producing a double. The problem seems like you are having is because of inconsistant varible types.
The folowing case does not work because there are two differant variable types:
double = integer / integer
A solution to this problem is to use a STATIC CAST. The following line could be read as "turn my (positiveIntegerCount) into a double before i divide by its length":
Plus Minus
You are viewing a single comment's thread. Return to all comments →
Most programing languages do not like when variable types mix with eachother. An integer divided by an integer produces a floating point in most cases, but the computer only works with variables that all have the same data type; such as a double divided by a double producing a double. The problem seems like you are having is because of inconsistant varible types.
The folowing case does not work because there are two differant variable types: double = integer / integer
A solution to this problem is to use a STATIC CAST. The following line could be read as "turn my (positiveIntegerCount) into a double before i divide by its length":