Accumulator problem/Function help

H1. I'm unable to get my accumulator to display the totalIncreasePercentages variable. I need the averageOfIncreases to display the average of the totalIncreasePercentages, I believe my logic is right but I don't know why it's always outputting 0.
Second, maybe I'm using the wrong function to load my array values and that's why the accumulator won't work? Do I need to use pass by value or reference instead?
Lastly, my output display doesn't look the greatest.The increase% is jammed up against the comment of whether the average is above,below,or equal to. I can't figure out the spacing necessary in the output.

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//Declaring global constants
const int NUM_EMPLOYEES = 5;

//Function Prototypes
void LoadItemArrays(string empNum[], double salary2017[], double salary2018[], double salaryIncrease[], double totalIncreasePercentages, double averageOfIncreases);
void OutputSalaryDisplay (string empNum[], double salary2017[], double salary2018[], double salaryIncrease[], double averageOfIncreases);

int main()
{
	string empNum[NUM_EMPLOYEES] = {};
	double salary2017[NUM_EMPLOYEES],
		salary2018[NUM_EMPLOYEES],
		salaryIncrease[NUM_EMPLOYEES],
		totalIncreasePercentages = 0,
		averageOfIncreases = 0,
		aboveAverage = 0,
		belowAverage = 0,
		equalToAverage = 0;
	int k = 0;

	//Function Calls
	LoadItemArrays(empNum, salary2017, salary2018, salaryIncrease, totalIncreasePercentages, averageOfIncreases);
	OutputSalaryDisplay(empNum, salary2017, salary2018, salaryIncrease, averageOfIncreases);


	return 0;
}


void LoadItemArrays(string empNum[], double salary2017[], double salary2018[], double salaryIncrease[], double totalIncreasePercentages, double averageOfIncreases)
{
	//declaring index variable 
	int k = 0;

	for (k = 0; k < NUM_EMPLOYEES; k++)
	{
		cout << "\nEnter an employee number" << endl;
		cin >> empNum[k];

		cout << "\nEnter the employee salary in 2017" << endl;
		cin >> salary2017[k];

		cout << "\nEnter the employee salary in 2018" << endl;
		cin >> salary2018[k];

		salaryIncrease[k] = salary2018[k] - salary2017[k];
		salaryIncrease[k] = salaryIncrease[k] / salary2017[k];
		salaryIncrease[k] = salaryIncrease[k] * 100;

		totalIncreasePercentages = totalIncreasePercentages + salaryIncrease[k];
		system("cls");

	}
	//Calculating the average of the increases
	averageOfIncreases = totalIncreasePercentages / NUM_EMPLOYEES;
}

void OutputSalaryDisplay(string empNum[], double salary2017[], double salary2018[], double salaryIncrease[], double averageOfIncreases)
{
	//Declaring index variable
	int k = 0;

	//Outputting headings
	cout << "Employee number" << left << setw(15) << "2017 Salary" << setw(18) << "2018 Salary" << right << setw(12) << "Increase %" << setw(12) << right << "Comment";
	
	//Creating a for loop to output the employees data that is stored in the arrays.
	for (k = 0; k < NUM_EMPLOYEES; k++)
	{
		cout << "\n\n" << left << setw(15) << empNum[k] << setw(18) << salary2017[k] << setw(12) << salary2018[k] << right << setw(12) << salaryIncrease[k] << setw(12) << right;
		
		//If statement to determine whether the increase is above, below, or equal to average. 
		if (salaryIncrease[k] > averageOfIncreases)
		{
			cout << "Above Average" << endl;
		}
		else if (salaryIncrease[k] < averageOfIncreases)
		{
			cout << "Below Average" << endl;
		}
		else
		{
			cout << "Equal to Average" << endl;
		}
	}
	cout << "The average of the increases is:" << averageOfIncreases;

  Put the code you need help with here.
Last edited on
For your LoadItemArrays function, try passing the scalar parameters as references if you want changes to them visible in main.
1
2
void LoadItemArrays(string empNum[], double salary2017[], double salary2018[], double salaryIncrease[], 
    double &totalIncreasePercentages, double &averageOfIncreases)
Thank you!
Topic archived. No new replies allowed.