C++ Function Definition Calculates the average of three input values

Description

C++ Function Definition Calculates the average of three input values

#include <iostream>
using namespace std;
int calc_av(int num1, int num2, int num3);   //Prototype
int main()//from   w  ww .ja  va 2  s. c om
{
   int num1, num2, num3;
   int avg;                 // Holds the return value.
   cout << "Please type three numbers (such as 23 54 85) ";
   cin >> num1 >> num2 >> num3;

   avg = calc_av(num1, num2, num3);
   cout << "\n\nThe average is " << avg;     // Print the return value.
   return 0;
}
int calc_av(int num1, int num2, int num3)
{
   int local_avg;  // Holds the average for these numbers.
   local_avg = (num1+num2+num3) / 3;
   return (local_avg);
}



PreviousNext

Related