Whats wrong with my code?

The following codes are able to run and all functions are working fine except for the maxPay function. My end goal is to find the person with the maxPay but in the codes below im trying to make sure the values from function showPay is brought forward to maxPay by doing a loop to show the Artists name and Artists pay for confirmation before I start to move on the the main focus of the programme.

Problem:
When I run the programme, function showPay is working fine but when I use the maxPay function (MENU 3) , the names of the 10 people will appear but their pay under payArray[] are all 0 for all 10 elements.

When I input their pay in MENU 1 which is not in this code but is working (so I wont put it here to waste your time to read it), the results from running the programme is as follows:
Amy 0
David 0
John 0
Helen 0
Mumu 0
William 0
Sunny 0
Rocky 0
Benny 0
Dawn 0
instead of showing out their total pay from the previous showPay function
which ive already made sure I updated the array via:
totalStaffPay = payArray[x] = totalStaffHours *10.0;

Additional Information:
If I copy and paste the code from the maxPay function into the showPay function, it works.

But once Include the use of the maxPay function, it doesn't work anymore. The pay array doesn't get transferred to the maxPay function.

Below is part of my programme.
Appreciate any help. Thanks.

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//Global definitions
  const int hours = 3;
const int staff = 10;
int payArray[staff] = {0,0,0,0,0,0,0,0,0,0};
string artists[staff] ={"Amy","David","John","Helen","Mumu","William","Sunny","Rocky","Benny","Dawn"};
int staffHours[staff][hours] = {{0,0,0},
                                {0,0,0},
                                {0,0,0},
                                {0,0,0},
                                {0,0,0},
                                {0,0,0},
                                {0,0,0},
                                {0,0,0},
                                {0,0,0},
                                {0,0,0}};


//Functions
void showMenu();
int enterPay(int staffHours[][hours],int);
int showPay(int[][hours],int);
void maxPay (int payArray[], int);
void checkout();


//MENU CASES


            case MENU_TWO:
            showPay(staffHours,staff);
            break;


            case MENU_THREE:
            maxPay(payArray,staff);
            break;


//SHOW PAY FUNCTION

int showPay(int[][hours],int staff)
{

    int totalStaffHours;
    double totalStaffPay;
    double allPay =0;
    double averagePay =0;
    int belowAverage =0;
    int aboveAverage =0;

    cout << fixed << showpoint << setprecision(2);

    cout << "\n\n";
    cout << "===================================\n";
    cout << "Pay Report: \n";
    cout << setw(12) << "\t\t";
    cout << setw(10) << "Hours \n";

     for (int x=0; x < staff; x++)
    {

        //To refresh the totalStaff Hours & Pay count
        totalStaffHours = 0;
        totalStaffPay =0.0;

        for (int y=0; y < hours; y++)
        {


        totalStaffHours += staffHours[x][y];

        }

    if (totalStaffHours <=30)
    {
        totalStaffPay = payArray[x] = totalStaffHours *10.0;
    }

    else
    {
        totalStaffPay = payArray[x] = 30*10.0 + (totalStaffHours - 30) * 10.0 * 1.5;
    }


    cout << setw(12) << artists[x] << "= $" << totalStaffPay ;
    cout << setw (10) << "\t" << totalStaffHours;


//MAX PAY FUNCTION

void maxPay(int payArray[],int staff)
{
    double highest;
    string highestArtist;

    for(int l=0;l<staff;l++)
    {
    cout << artists[l] << "\t" << payArray[l] << endl;
    }

    cout << "\n\n";

}
Last edited on
closed account (48T7M4Gy)
Your problem is payArray element values are not being updated.

I suggest you avoid double = lines like line 76.

closed account (48T7M4Gy)
Also, not a big deal, int l line 96 etc is not a good name choice as it is so easily confused with the number '1'
Just realised the problem with my programme lies in menu 1 which I did not post it here. Nevertheless, solved it, and thanks for the hasty reply kemort.
Topic archived. No new replies allowed.