• + 0 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":

    myDoubleAnswer = static_cast<double>(positiveIntCount) / n
    
    static_cast<type>(variableToStaticCast)