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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <iomanip>

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..
Thanks for the quick replys!

@ Useless (12)

Your solution worked perfectly.
Last edited on
Topic archived. No new replies allowed.