double getInput (double hoursworked, double payrate )
{
// request the total hours worked
std::cout<< "\n Please enter the total hours worked \n";
// input the total hours worked
std::cin>> hoursworked;
//request employee's earning wage information
std::cout<<"\nEnter the pay rate\n";
// input payrate for requested employee
std::cin>>payrate;
return ??;
As lb mentioned instead of passing by copies pass by reference you would do this like this
1 2 3 4
void getInput( double &hoursworked , double &payrate )
{
//same body you have will work
}
It will directly modify the variables being passed through the function instead of creating a copy of it then modifying that one.
That being said an example would be this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void ex( int &a , int b )
{
a = 2;
b = 2;
std::cout << "During: a = " << a << " | b = " << b << std::endl;
}
int main()
{
int a = 1 , b = 1;
std::cout << "Before: a = " << a << " | b = " << b << std::endl;
ex( a , b );
std::cout << "After: a = " << a << " | b = " << b << std::endl;
}
As you can see b is only modified inside of the local function of ex where as a is being modified inside of the local function and also modified inside of the main function since it is modifying the value of a at the reference( memory address of a ).