Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please figure out how to make program output the name and total time an employee

ID: 3629987 • Letter: P

Question

Please figure out how to make program output the name and total time an employee spends on the job.
Here is code I have for now:
I've updated the code with the missing portion

#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;
bool arrivalAM;
int departureHr;
int departureMin;
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;
cin.get(discard);
cout << endl;
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 << "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;

        int arrivalMin;
        bool arrivalAM;

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

void timeOnJob(int arvHr, int arvMin, bool arvIsAM, int depHr, int depMin, bool depIsAM)
{
int arvTimeInMin;
int depTimeInMin;
int timeOnJobInMin;

arvTimeInMin = arvHr * 60 + arvMin;
depTimeInMin = depHr * 60 + depMin;

if((arvIsAM == true && depIsAM == true) ||
(arvIsAM == false && depIsAM == false))
 
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)
{
timeOnJobInMin = depTimeInMin - arvTimeInMin;
cout << "Time spent of job: "
             << timeOnJobInMin / 60 << " hour(s) and "
             << timeOnJobInMin % 60 << " minutes." << endl;

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


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

Explanation / Answer

Your main is fine, but your function timeOnJob() is not complete. Your condition statement if(arvIsAM == true) can be written as if(arvIsAM) since arvIsAM is a boolean itself, you don't have to use operator==. Similarly, use if(!arvIsAM) instead of if(arvIsAM == false) void timeOnJob(int arvHr, int arvMin, bool arvIsAM, int depHr, int depMin, bool depIsAM) { int arvTimeInMin; int depTimeInMin; int timeOnJobInMin; arvTimeInMin = arvHr * 60 + arvMin; depTimeInMin = depHr * 60 + depMin; if (arvIsAM != depIsAM) { if (!arvIsAM) { cout