problems with switch case using arrays an functions

Hello everyone I'm fairly new to programming an am working on an assignment where I'm using a menu using a switch statement with arrays and functions. I'm gradually inputting the code and trying to run each function but keep getting an error saying "undefined reference to ..." . I've tried to look on the site but like I said I'm very new and I barely understand what's going on. I 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
#include <iostream>
#include <iomanip>
using namespace std;

const int namelen = 65;
const int size = 20;

void printMenu();
void addEmployees(char[][namelen], double[], double[], int&);
void displayAllEmployees(char[][namelen], double[], double[], int);

int main()
{
    int count = 0, choice;
    char name[size][namelen];
    double rate[size], hours[size];

    do
    {
        printMenu();
        cin >> choice;

        while (count == 0 && choice != 1)
        {
            cout << "You must add atleast one employee to the database";
            cout << "before selecting the other options. " << endl;
            cin >> choice;
        }

        switch(choice)
        {
            case 1:
                addEmployees(name, rate, hours, count);
                break;
            case 2:
                displayAllEmployees(name, rate, hours, count);
                break;
            case 0:
                break;
            default:
                cout << "Error: Invalid menu choice. ";
                cout << "Please select valid menu choice: ";
                cin >> choice;
        }
    }
    while (choice != 0);
    cout << "Thank you. Goodbye. " << endl;
    return 0;
}

void printMenu()
{
    cout << "Welcome to the Employee Paycheck Calculator " << endl;
    cout << "=========================================== " << endl;
    cout << "1.  Add employee record(s) to the database " << endl;
    cout << "0.  Exit " << endl;
    cout << "=========================================== " << endl;
    cout << "Enter selection:  ";
}

void addEmployees(char name[], double rate[], double hours[], int &count)
{
    cout << "How many employees do you wish to add? ";
    cin >> count;

    while (count < 1 || count > 65)
    {
        cout << "That is an invalid size. ";
        cout << "You must enter a value between 1 and 100. " << endl;
        cout << "How many employees do you wish to add? ";
        cin >> count;
    }

    for (int i = 0; i < count; i++)
    {
        cout << endl;
        cout << "Enter Employee " << i << " name: ";
        cin >> name[i];

        cout << "Enter " << name[i] << "'s pay rate: ";
        cin >> rate[i];

        cout << "Enter " << name[i] << "'s weekly hours: ";
        cin >> hours[i];
    }
}

void displayAllEmployees(char name[], double rate[], double hours[], int num)
{
    cout << endl;
    cout << "Index" << "  " << "Name" << "\t\t";
    cout << "Rate" << "\t" << "Hours" << endl;

    for (int i = 0; i < num; i++)
    {
        cout << num << "  " << name[i] << "\t\t";
        cout << rate[i] << "\t" << hours[i] << endl;
    }
}
Last edited on
Hi,

did you really add all functions that you want to call ??

If i didn't miss it, you have a prototype for "printAllPaychecks" but no function with this name ...
and the compiler won't tolerate that. Even if you don't really want to enter Menu-point ... the function is nessecary to compile because you link it statically.
yeah I was adding each one by one and running them each to make sure they run correctly, but perhaps I need to add them all first. will do so then edit my message.
Topic archived. No new replies allowed.