Write a void function called TimeAdd that takesparameters representing two times
ID: 3614922 • Letter: W
Question
Write a void function called TimeAdd that takesparameters representing two times in days, hours, and minutes, andthen adds those parameters to get a new time. Each part ofthe time is an int. Hours range from 0 to23, while minutes range from 0 to 59. There is no limit on therange of days. We assume that the time to be added ispositive. The values in the parameters representing the firsttime are replaced by the result of adding the two times.Here is an example call in which 3 days, 17 hours, 49 minutes isadded to 12 days, 22 hours, and 14 minutes:
days = 12;
hours = 22;
minutes = 14;
TimeAdd(days, hours, minutes, 3, 17, 49)
After the call, the values in the variables are as follows:
days = 16
hours = 16
minutes = 3
Explanation / Answer
#include<iostream>
using namespace std;
void TimeAdd(int &,int&,int&,int,int,int);
int main()
{int days=12,hours=22,minutes=14;
TimeAdd(days,hours,minutes,3,17,49);
cout<<"Days = "<<days<<endl;
cout<<"Hours = "<<hours<<endl;
cout<<"Mnutes = "<<minutes<<endl;
system("pause");
return 0;
}
void TimeAdd(int &d,int& h,int& m,int dd,int hh,intmm)
{int extra;
d+=dd;
h+=hh;
m+=mm;
extra=m/60;
m%=60;
h+=extra;
extra=h/24;
h%=24;
d+=extra;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.