### Array

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071`` ``````// Includes #include "stdafx.h" #include 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.