### Transfering values between functions

How do I maintain my values input into the “getinput “ function in my main function? What I’m trying to do is call the function, have those instructions run. The user then inputs the appropriate values and the function returns those inputted values in the main function. So as the program continues to run, it uses those values to calculate gross and net pay.

I would appreciate complete but simples answers. I’m still rather new to programming.

 12345678910111213141516171819202122232425262728293031323334353637383940 #include #include using namespace std; void getinput (int, double); void computePay (int, double, double, double); int main () { int hours = 0; double rate = 0; double net = 0; double gross = 0; getinput (hours, rate); computePay ( hours, rate, net, gross); return 0; } void getinput (int hours, double rate) { cout << "Enter the amount of hours worked: "; cin >> hours; cout << endl; cout << "Enter the hourly rate of pay: "; cin >> rate; cout << endl; } void computePay (int hours, double rate, double net, double gross) { gross = hours * rate; net = gross - (gross *.15); cout << fixed << setprecision (2) << "Gross Pay: " << gross << endl; cout << fixed << setprecision (2) << " Net Pay: " << net << endl; }
http://en.wikipedia.org/wiki/Reference_(C%2B%2B)

void getinput( int& hours, double& rate )
Just pass your function argument by reference and that will work for you..