Average of 3 numbers (included number rounding)

The following code snippet calculates the average of 3 numbers.
setprecision() sets the decimal precision.

Code Explanation

LineDescription
7Declares the variables a, b, c and avg of type float
10 – 12Initializes the variables a, b and c with the values 14, 8 and 16
14Calculates the average of variable a, b and c
17Outputs the mean value via the setprecision() function
#include <iostream>
#include <iomanip>
using namespace std;

int main () {
    // declare variables
    float a, b, c, avg; 

    // initialize variables
    a = 14;
    b = 8;
    c = 16;
    
    avg = (a + b + c) / 3;

    /* setprecision(n): setting the decimal places and rounding */
    cout << "Average of " << a << ", " << b << " and " << c << " is: " << setprecision(4) << avg << endl;
}
Output
Average of the numbers 14, 8 and 16 is: 12.67