Calculate Average of Positive Numbers
Your task is to implement the calculateAverage function. This function takes an array of integers (arr) and its size (size) as input.
The function should:
- Iterate through the array to find all positive numbers.
- Calculate the sum of these positive numbers.
- Count how many positive numbers were found.
- Return the average of the positive numbers.
Important Considerations:
- If the array contains no positive numbers or if the
sizeis 0 (representing an empty array), the function should return0.0to prevent division by zero and correctly handle these edge cases. - Ensure floating-point division is used for the average calculation.
calculate_average_of_positive_numbers.cpp
Loading...
Use the "Verify Solution" button to get AI feedback on your c++ code.