Array

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
// Includes
#include "stdafx.h"
#include <iostream>
using namespace std;

// Main
int main()
{
	//Variables
	char names[10];
	int salary[10];
	int k,
		n,
		sum;
	double average;
	sum = 0;
	average = 0;
	k = 0;
	n = 0;

	// Employee Names
	for (k = 0; k < 10; k++)
	{
		cout << "Enter employee name: " << endl;
		cout << k + 1 << ". ";
		cin.getline(names, 256);
	}

	cout << "\n";

	//Salary
	for (n = 0; n < 10; n++)
	{
		cout << "Enter the salary for employee: " << endl;
		cout << n + 1 << ". $";
		cin >> salary[n];
		sum = sum + salary[n];
	}

	average = sum / 10;

	cout << "\n";
	
	for (k = 0; k < 10; k++)
	{
		cout << "The salary for " << names[k] << " is $" << salary[n] << endl;
	}

	cout << "\nThe average salary is $" << average << endl;
	
	for (n = 0; n < 10; n++)
	{
		if (salary[n] < average)
		{
			k = k + 1;
		}
		else if (salary[n] > average)
		{
			k = k + 1;
		}
	}
	cout << "The number of salaries above average is " << k << endl;
	cout << "The number of salaries below average is " << k << endl;

	cout << "\nPress ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();

	return 0;
}


at lines 44-47, it is supper to display all the employees name and salaries, but it is displaying as so, say the last name is kathy, it displays like this


the salary for k is $-860.....
the salary for a is $-860.....
the salary for t is $-860.....
so on and so forth.

it should display like this

the salary for kathy is $salary amount.

the salary suppose to be displayed is also a random number and its the same for every line.

I also need help with the below and above average loop, it displays the same for both.

Can anyone help me fix these problems please?
Aloha Reaper

Your Array for names stores characters instead of strings. change it to string then you can use cin>>names[k] for the users input.
Aloha to you you Tertius,

Ok, I got that part fixed the names work, now i need the below average and above average, and also the salary for the names is being displayed as a random number like -86000000. or something like that, how do i fix this.
Last edited on
I fixed the salary issue, so now i need help on the below and above average part.
Nevermind, I have fixed it thank you for the help.
Topic archived. No new replies allowed.