Finding multiple lowest numbers


Im creating a programme to find the lowest paid performer.
Below is the function that allows me to carry out this task.
How can I improve it to include multiple artists instead of just one lowest paid artist.
EXAMPLE: jane earns $10 and 10 other artists earn $20 so jane is the lowest. But suddenly, someone called tom enters and earns $10 too. so what do I do to improve the programme so that both tom and jane's name are recorded.

Standard cplusplus rules apply here, just give me some hints like what c++ concepts can I use etc and don't give me the answer.

Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void minPay(double payArray[staff],int staff)
{

    for(int m=0; m < staff; m++)
    {
        if (payArray[m] <= lowest)
        {
            lowest = payArray[m];
            lowestArtist = artists[m];
        }
    }

    cout << "===========================\n";
    cout << "Lowest Pay Artist(s): \n";
    cout << lowestArtist << "\t" << "$" << lowest << endl;
    cout << "===========================\n";
    cout << "\n\n";


}
Last edited on
Hi,

Can you put the lowest paid into another array?
Tried it.
This is my new code.
payArray[] is the total pay of the 10 staff
artists[] is a string array holding the name of the 10 artists
highestPay[] is a new array to store the pay of the new highest
highestArtists[] is a new array to store the names of the highest.

There are errors with the programme:
Result will be as follows:
Highest Pay Artist(s)
$0.00
$0.00
$0.00
$0.00
$0.00
$0.00
$0.00
$0.00
$0.00
$0.00

Any suggestions why is this so?

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

void maxPay(double payArray[staff],int staff)
{

    highest = payArray[0];

    for(int n=0; n < staff; n++)
    {
        if (payArray[n] >= highest)
        {
            payArray[n] = highestPay[n];
            artists[n] = highestArtists[n];
        }
    }

    cout << "===========================\n";
    cout << "Highest Pay Artist(s): \n";

    for (int u=0;u<staff;u++)
    {
    cout << highestArtists[u] << "\t" << "$" << highestPay[u] << endl;
    }
    cout << "===========================\n";
    cout << "\n\n";


}
Hi,

Just go with this for a minute:

Initialise the highestPay and highestArtists with some odd looking value like 999 or 777 say. See what happens. This might help to see what you did wrong.

Sometimes, initialising with weird values can help with debugging.

A better thing to help with debugging, is a debugger :+) If using an IDE, there should be an easy to use GUI debugger built in. Have a watch-list of variables to keep an eye on, step through the code from a beak-point, 1 line at a time, see how your values change and deduce what went wrong.

With your code in your other post, you have a lot global's - that is bad. Keep the scope of your variables as tight as possible. Pass as arguments to functions whatever variables they need.

Good Luck !!
Topic archived. No new replies allowed.