void functions(help)

Hi i am new to this site. I this code from my book that i had to rearrange and put it in the correct order and make it functional, so i have it all in order and i keep getting an
(error: cannot use this function). I anyone can tell me what i am doing wrong i would appreciate it. oh and by the way i am using code blocks if that matters

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
  #include <iostream>

  #include<string>

  using namespace std;

void timeOnJob(int arvHr, int arvMin, bool arvIsAM, int depHr, int depMin, bool depIsAM);

int main()
{
string employeeName;
int arrivalHr;
int arrivalMin;
int timeOnJob;

int departureHr;
int departureMin;
bool arrivalAM;
bool departureAM;


char response;
char discard;
char isAM;

cout << "This program calculates the total time spent by an "
<< "employee on the job." <<endl;
cout << "To run the program, enter (y/Y): ";
cin >> response;
cout << endl;
cin.get(discard);

while (response =='y' || response == 'Y')
{
cout << "Enter employee's name: ";
getline(cin, employeeName);
cout << endl;

cout << "Enter arrival hour: ";
cin >> arrivalHr;
cout << endl;
cout << "Enter arrival minute: ";
cin >> arrivalMin;
cout << endl;
cout << "Enter (y/Y) if arrival is before 12:00PM: ";
cin >> isAM;
cout << endl;

if (isAM == 'y' || isAM == 'Y')
    arrivalAM = true;

else
    arrivalAM = false;

cout << "Enter departure hour: ";
cin >> departureHr;
cout << endl;
cout << "Enter departure minute: ";
cin >> departureMin;
cout << endl;
cout << "Enter (y/Y) if departure is before 12:00PM: ";
cin >> isAM;
cout << endl;

if (isAM == 'y' || isAM == 'Y')
departureAM = true;
else
departureAM = false;

cout<< employeeName << endl;
timeOnJob(arrivalHr, arrivalMin, arrivalAM, departureHr, departureMin, departureAM);

cout << "Run program again (y/Y): ";
cin >> response;
cout << endl;
cin.get(discard);
}

return 0;
}
void timeOnJob(int arvHr, int arvMin, bool arvIsAM, int depHr, int depMin, bool depIsAM)
{// beginning of timeOnJob Function
    int arvTimeInMin;
    int depTimeInMin;
    int timeOnJobInMin;

    if ((arvIsAM == true && depIsAM == true)|| (arvIsAM == false && depIsAM == false))
    {
    cout << "Invalid input." << endl;
    }

    else if (arvIsAM == true && depIsAM == false)
    {
    arvTimeInMin = arvHr * 60 + arvMin;
    depTimeInMin = depHr * 60 + depMin;
    timeOnJobInMin = (720 - arvTimeInMin) + depTimeInMin;
    cout << "Time spent of job: "
    << timeOnJobInMin / 60 << " hour(s) and "
    << timeOnJobInMin % 60 << " minutes." << endl;
    }
    else
        if (arvTimeInMin <= depTimeInMin)
        {// beginning of if
        timeOnJobInMin = depTimeInMin - arvTimeInMin;
        cout << "Time spent of job: "
        << timeOnJobInMin / 60 << " hour(s) and "
        << timeOnJobInMin % 60 << " minutes." << endl;
        }// end of if
        else
        cout << "Invalid input." << endl;

}// end of timeOnJob function
Replace all "timeOnJob" with "timeOnJob2" and the code will compile.

But the real problem is this :
1
2
3
4
5
6
int main()
{
string employeeName;
int arrivalHr;
int arrivalMin;
int timeOnJob; // Remove this variable or change its name, the code will compile 
Last edited on
@SakurasouBuster in the main function only?
Remove line 14. The variable declared on that line has the same identifier as the function you're trying to call on line 71.
That worked thanks alot!
Topic archived. No new replies allowed.