String, Multidimensional Arrays

Im doing a programme with a menu that allows the user to update the working hours of 10 people. im using Code blocks and am able to run the programme. However, the problem is that during the input of artist's hours, it will come out as:
Enter 1's hours #1:
instead of the desired
Enter Amy's hour #1:

Below is Part of the programme.
Would appreciate any advice 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
#include <iostream>
#include <sstream>
#include <String>
#include <iomanip>

using namespace std;

const int hours = 3;
const int staff = 10;
string artists[staff] ={"Amy","David","John","Helen","Mumu","William","Sunny","Rocky","Benny","Dawn"};
int staffHours[staff][hours];

//Functions
int enterPay(int[][hours],int);

int main()
{
    int choice; //Menu choice

    //Constants for menu
    const int MENU_ONE =1,
              MENU_TWO =2,
              MENU_THREE =3,
              MENU_FOUR =4,
              MENU_FIVE =5;

    do
    {
     showMenu();
     cin >> choice;

    //Validate choice selected for menu
    while (choice < MENU_ONE||choice >MENU_FIVE)
    {
       cout << "Please enter a valid choice: ";
       cin >> choice;
    }

    if (choice != MENU_FIVE)
    {
        switch (choice)
        {
            case MENU_ONE:
            enterPay(staffHours,staff);
            break;


            case MENU_TWO:
            break;


            case MENU_THREE:
            break;


            case MENU_FOUR:
            break;
        }


    }


    } while (choice != MENU_FIVE);

    checkout();
    return 0;
}

int enterPay(int[][hours],int staff)
{
    for (int x=0; x < staff; x++)
    {
        for (int y=0; y < hours; y++)
        {

            cout << "Enter " << x+1 << "'s hours #" << y+1 << " :";
            staffHours[x][y]= getInt();
            }
        }
Last edited on
closed account (48T7M4Gy)
line 77:

cout << "Enter " << artists[x+1] << "'s hours #" << y+1 << " :";

Check also that x+1 can't go out of range.
Last edited on
Thanks kemort. Solved it.
However I have a question. In this seperate function, I only defined the multidimensional array and not the string array so why does the string array still work even if I did not define it under the () after the enterPay().
Any one with any idea? Or any links that I can read up on this?
Thanks.
closed account (48T7M4Gy)
To be honest I didn't notice it at the time but now that you mention it the string array works because you have given it global scope by setting it outside main. We call this good luck for you. Even though it's not a good idea to make it global.
closed account (48T7M4Gy)
BTW: The solution I suggested still applies. What you possibly need to do once you shift the arrays into main is read up on passing arrays. There are tutorials on this site if needed. :)
I see. Thanks for the help!
Topic archived. No new replies allowed.