24. Program that inputs two times in hh:mm:ss format, adds both times and display the total time.

Chapter 4: 

Input And Output

Programming Exercise

Problem # 24:

Write a program that inputs two times in hh:mm:ss format, adds both times and
display the total time.

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int hh1, hh2, mm1, mm2, ss1, ss2, hh=0, mm=0, ss=0;
    cout<<"Enter time 1 in hh:mm:ss format : ";
    cin>>hh1>>mm1>>ss1;  
    cout<<"Enter time 2 in hh:mm:ss format : ";
    cin>>hh2>>mm2>>ss2;
    ss = ss1 + ss2;
    mm = ss / 60;
    ss = ss % 60;
    mm = mm + (mm1 + mm2);
    hh = mm / 60;
    mm = mm % 60;
    hh = hh + (hh1 + hh2);
    cout<<"Sum of two times is : "<<hh<<":"<<mm<<":"<<ss<<endl;
    return 0;
}

Let me know in the comment section if you have any question.

Previous Post:
23. Program that inputs Basic Salary and calculates 35% dearness allowance, 25% house rent and then display the gross salary.

Comments