Compute the Average

  • + 0 comments

    Wrong Code uses integer arithmetic ($((sum + num))), which truncates floating-point numbers, leading to incorrect results when decimals are involved. For example, with inputs 1.5, 2.5, and 3.0, the sum becomes 6, resulting in an incorrect average of 2.000.

    Correct code uses bc for all arithmetic, which handles both integers and floating-point numbers correctly. With the same inputs, the sum becomes 7.0, and the correct average of 2.333 i