C++ Reference variables from function

Description

C++ Reference variables from function

#include <iostream>
using namespace std;
void newval(double&, double&);  // prototype with two reference parameters
int main()//  w w  w. j  a  va2s  .  co m
{
   double firstnum, secnum;
   cout << "Enter two numbers: ";
   cin  >> firstnum >> secnum;
   cout << "\nThe value in firstnum is: " << firstnum << endl;
   cout << "The value in secnum is: " << secnum << "\n\n";
   newval(firstnum, secnum);   // call the function
   cout << "The value in firstnum is now: " << firstnum << endl;
   cout << "The value in secnum is now: " << secnum << endl;
   return 0;
}
void newval(double& xnum, double& ynum)
{
   cout << "The value in xnum is: " << xnum << endl;
   cout << "The value in ynum is: " << ynum << "\n\n";
   xnum = 89.5;
   ynum = 99.5;
   return;
}



PreviousNext

Related