Ask Question
16 April, 15:45

Suppose John and Bil lworked for sometime and wewant tocalculate the total time both of them worked. Write a program that reads number of days, hours, minutes each of them worked, and prints the total time both of them worked together as days, hours, minutes.

+5
Answers (1)
  1. 16 April, 17:20
    0
    We have the following C+ + code with appropriate comments

    Explanation:

    #include

    using namespace std;

    //execution of program starts from here

    int main ()

    {

    //all instance variables for john

    int day_john, hour_john, minutes_john;

    //all instance variables for bill

    int day_bill, hour_bill, minutes_bill;

    //total worked

    int total_day, total_hour, total_min;

    //after we convert min to hour, we have an extra_hour, which we add in total hour

    int extra_hour = 0;

    int extra_day = 0;

    //ask the total work time of john

    cout << "Enter the number of days John worked : ";

    cin >> day_john;

    cout << "Enter the number of hours John worked : ";

    cin >> hour_john;

    cout << "Enter the number of minutes John worked : ";

    cin >> minutes_john;

    //ask the total work time of Bill

    cout << "Enter the number of days Bill worked : ";

    cin >> day_bill;

    cout << "Enter the number of hours Bill worked : ";

    cin >> hour_bill;

    cout << "Enter the number of minutes Bill worked : ";

    cin >> minutes_bill;

    //calculate total worked of both together

    //if total min are greater than 60, increase the hour by 1

    if (minutes_john + minutes_bill > 60)

    {

    total_min = (minutes_bill + minutes_john) - 60;

    extra_hour = 1;

    }

    else

    {

    total_min = minutes_bill + minutes_john;

    }

    //similarly for hours

    if ((hour_john + hour_bill + extra_hour) > 24)

    {

    total_hour = (hour_john + hour_bill + extra_hour) - 24;

    extra_day = 1;

    }

    else

    {

    total_hour = hour_john + hour_bill + extra_hour;

    }

    total_day = day_john + day_bill + extra_day;

    //print all

    cout << "The total time both of them worked together is: "

    << total_day << " days, " << total_hour << " hours and " << total_min << " min";

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Suppose John and Bil lworked for sometime and wewant tocalculate the total time both of them worked. Write a program that reads number of ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers