Arrays homework question

I'm writing a program for class where employee names and pays are read from an input file into arrays. How would I go about writing the code to get this function to display the correct name from the array for the employee with the largest pay check? The function itself works as far as determining which value is the largest, I'm just drawing a blank on how to cout the correct name.
1
2
3
4
5
6
7
8
9
10
11
void sort(string fName[], string lName[], double actualPay[], int count)
{
	double bigPay=actualPay[0];
	for(int b=0; b<count; b++)
	{
		if(bigPay < actualPay[b])
			bigPay = actualPay[b];
	}

cout << "Paycheck Amount: $" << bigPay << endl; 	 
}
I would assume that, say, fname[3] goes with lname[3] goes with actualPay[3]. So you need to save the index where you found the biggest pay. Make a new variable for this. Also, if you're trying to print the highest paid, don't call the function 'sort', call it something like 'printHighestPaid'.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void printHighestPaid(string fName[], string lName[], double actualPay[], int count)
{
    double bigPay=actualPay[0];
    int indexOfBigPay = 0;
    for(int b=0; b<count; b++)
    {
        if(bigPay < actualPay[b])
        {
            bigPay = actualPay[b];
            indexOfBigPay = b;
        }
    }

    //do stuff with fname[indexOfBigPay], lname[indexOfBigPay], actualPay[bigPay] 
}
Last edited on
Ahh I see thank you very much.
I had a bad edit in there for a couple seconds, make sure you look at the most recent edit of my first post. :)
Topic archived. No new replies allowed.