C++ Program to implement sum of two input times
#include<iostream.h>
#include<conio.h>
struct time
{
int hrs;
int mins;
};
time sumtime(time,time);
main()
{ clrscr();
time a,b,c;
cout<<"enter first time in hrs:";
cin>>a.hrs;
cout<<"enter first time in mins:";
cin>>a.mins;
cout<<"enter second time in hrs:";
cin>>b.hrs;
cout<<"enter second time in mins:";
cin>> b.mins;
c = sumtime(a,b);
cout<<"the time in hrs:";
cout<< c.hrs;
cout<<"the time in mins:";
cout<<c.mins;
getch();
return 0;
}
time sumtime(time a1,time a2)
{
time a3;
a3.hrs = a1.hrs+a2.hrs;
a3.mins= a1.mins+a2.mins;
if (a3.mins==60)
{
a3.hrs=a3.hrs+1;
a3.mins=0;
}
if (a3.mins>60)
{
int h=a3.mins/60;
a3.hrs=a3.hrs+h;
a3.mins=a3.mins-60;
}
return a3;
}
Related Posts : C++ Programs
0 comments:
Post a Comment