Calling function help?

Hey everyone, me again. I'm learning more about calling functions and pass by references this week in my class. For this program, it's supposed to show 10500 and 11000 for the raises. I can get the first one to show up, but not the second one. I thought it was because they shared a variable, so I tried to change that. But now it won't even get past the input with salary1 on line 17. If I take it out, it works up until the tenPercentRaise portion of the code, thus outputting a 0 (since salary1 doesn't get a value since I have to take it out). Any ideas on what's going on?

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
#include <cstdlib>
#include <iostream>
using namespace std;

void fivePercentRaise(double &);
void tenPercentRaise(double &);

int main()
{
	double salary = 0.0;
	double salary1 = 0.0;
	
	cout << "Please enter current salary: ";
	cin >> salary >> salary1;
	
	fivePercentRaise(salary);
	
	tenPercentRaise(salary1);	

system("pause");
return 0;
}

void fivePercentRaise(double &sal)
{
	sal = sal + (sal * 0.05);
	cout << "New salary if you receive a 5% raise: " << sal << endl;
}

void tenPercentRaise(double &sal)
{
	sal = sal + (sal * 0.10);
	cout << "New salary if you receive a 10% raise: " << sal << endl;
}
Last edited on
I got it after messing around with it for a bit. I found out you cant string cin together like that, so I just set salary1 equal to salary after input was stored for salary.
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
#include <cstdlib>
#include <iostream>
using namespace std;

void fivePercentRaise(double &);
void tenPercentRaise(double &);

int main()
{
	double salary = 0.0;
	double salary1 = 0.0;
	
	cout << "Please enter current salary: ";
	cin >> salary;
	
	salary1 = salary;
	
	fivePercentRaise(salary);
	
	tenPercentRaise(salary1);	

system("pause");
return 0;
}

void fivePercentRaise(double &sal)
{
	sal = sal + (sal * 0.05);
	cout << "New salary if you receive a 5% raise: " << sal << endl;
}

void tenPercentRaise(double &sal)
{
	sal = sal + (sal * 0.10);
	cout << "New salary if you receive a 10% raise: " << sal << endl;
}
The way you had the cin statements is like you would have TWO salaries inputted by the user, each stored in their own variable. Like:
1
2
cin >> salary;
cin >> salary1;
Last edited on
Topic archived. No new replies allowed.