C++ Function Parameter Reference Mix pass by value parameter and pass

Description

C++ Function Parameter Reference Mix pass by value parameter and pass

#include <iostream>
using namespace std;
void calc(double, double, double, double&, double&);  // prototype
int main()/*from w  w  w.  j a va 2  s .  com*/
{
   double firstnum, secnum, thirdnum, sum, product;
   cout << "Enter three numbers: ";
   cin  >> firstnum >> secnum >> thirdnum;
   calc(firstnum, secnum, thirdnum, sum, product);  // function call
   cout << "\nThe sum of the numbers is: " << sum << endl;
   cout << "The product of the numbers is: " << product << endl;
   return 0;
}
void calc(double num1, double num2, double num3, double& total, double& product)
{
   total = num1 + num2 + num3;
   product = num1 * num2 * num3;
   return;
}



PreviousNext

Related