function and array trouble

Hello everyone I am working on a homework assignment. I'm having trouble with the last portion of the code that asks to input a number that corresponds to an employee number then it will print out that employees name, pay rate, hours worked, and weekly pay. I'm getting an error saying that I have to define error: cannot convert 'double' to 'double*' for argument '2' to 'void printEmployeePaycheck(char*, double*, double*)'
. I tried to alter the parameters but no luck so far. Any help is appreciated and if there is anything off about my code I'd like to hear(read) it.

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

const int NAMELEN = 65;
const int SIZE = 20;

void printMenu();
void addEmployees(char name[][NAMELEN], double rate[], double hours[], int &count);
void displayAllEmployees(char name[][NAMELEN], double rate[], double hours[], int count);
void printEmployeePaycheck(char name[], double rate[], double hours[]);

int main()
{
    int count=0, choice;
    char name[SIZE][NAMELEN];

    double rate[SIZE], hours[SIZE];

    do
    {
        printMenu();
        cin >> choice;
        cout << endl;

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

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

void printMenu()
{

    cout << endl;
    cout << "Welcome to the Employee Paycheck Calculator " << endl;
    cout << "=========================================== " << endl;
    cout << "1.  Add employee record(s) to the database " << endl;
    cout << "2.  Print all employee records " << endl;
    cout << "3.  Print the paycheck for one employee " << endl;
    cout << "0.  Exit " << endl;
    cout << "=========================================== " << endl;
    cout << "Enter selection:  ";
}

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

    while (count < 1 || count > 20)
    {
        cout << "That is an invalid size. ";
        cout << "You must enter a value between 1 and 20. " << 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.ignore();
        cin.getline(name[i], NAMELEN);

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

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

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

    for (int i = 0; i < count; i++)
    {
        cout << i << "\t" << name[i] << "\t\t";
        cout << rate[i] << "\t" << hours[i] << endl;
    }
}

void printEmployeePaycheck(char name[], double rate[], double hours[])
{
    int i;
    int count = 0;
    double pay = rate[i] * hours[i];

    for (i = 0; i < count; i++)
    {
        cout << "Enter an Employee Number: ";
        cin >> i;

        while (i < 1 || i > count)
        {
            cout << "Error: this number does not correspond to an employee. ";
            cout << "Please enter a valid number. " << endl;
            cin >> i;
        }
    }

    cout << "Employee: " << name[i] << "\t\t" << "Rate: " << rate[i];
    cout << "\t" << "Hours: " << hours[i] << "\t" << "Weekly Pay: ";
    cout << pay << endl;
}


  
Last edited on
On line 128, you are missing a '}' to close off the 1st while-loop. You really don't need 2 of the same loop to complete that task.

Your array in the getEmployeeNumber function is 2-Dimensional, but you are passing it as a 1-Dimensional array into your printEmployeePaycheck function. try changing this?
I accidently added the extra loop while pasting it to the post. So how would I change the function of getEmployeeNumber to pass it as a 2d array, though what I'm trying to pass is just the employee number (empNum) to the function printEmployeePaycheck. Or is there a way to just add all of this to the "print" function?
in your parameter, just pass the employee number then put that into the array in the printEmployeePaycheck function. You should pass them separately, but by not passing the array as 2-Dimensional, it could be a problem.

Check out this link on passing arrays as function parameters:
http://stackoverflow.com/questions/8767166/passing-2d-array-to-function
okay I've rewritten the code but i'm still getting an error of;

hw6.cpp:45:42: error: cannot convert 'char (*)[65]' to 'char*' for argument '1' to 'void printEmployeePaycheck(char*, double*, double*)'


don't even know if this is the correct way to write the function, but from what i see all my parameters seem to match in the right places, i don't know why i'm still getting this error.
Topic archived. No new replies allowed.