Ok so basically I'm working with parallel arrays. One stores the name of an Employee and the other the rate of their pay. Eventually I am allowing the user to input the data....then outputting the highest and lowerst paid employee. However I am having a problem inserting the name into the array. I am completely confused as to what I'm doing wrong. Couldn't find any info on it. Any help would be much appreciated my final is tomorrow.
Code:
#include <iostream>
#include<iomanip>
#include<string>
using namespace std;
const int elements = 15;
void insertInfo(char name[], double rate[], int elements);
void sort(char name[], double rate[]);
void printExtremes(char name[], double rate[], int elements);
int main()
{
char name[elements];
double rate[elements];
insertInfo(name, rate, elements);
printExtremes(name, rate, elements);
return 0;
}
void insertInfo(char name[], double rate[], int elements) // Having trouble with this function
{
int index = 0;
cout << "Enter last name and rate of pay: ";
for (index = 0; index < elements; index++)
{
cin.get(name,29,'\n');
cin >> rate[index];
}
}
void printExtremes( char name[], double rate[], int elements)
{
double largestRate;
double smallestRate;
char largestName;
char smallestName;
int index;
int maxIndex = 0;
for (index = 1; index < elements; index++)
if (rate[maxIndex] < rate[index])
maxIndex = index;
largestRate = rate[maxIndex];
largestName = name[maxIndex];
for (index = 1; index < elements; index++)
if (rate[maxIndex] > rate[index])
maxIndex = index;
smallestRate = rate[maxIndex];
smallestName = name[maxIndex];
cout << "The highest paid employee is " << largestName << setfill ('-') << setw(20) << "$" << largestRate << endl;
cout << "The lowest paid employee is " << smallestName << setfill ('-') << setw(20) << "$" << smallestRate << endl;
}