create a structure called time.its three members ,all types int,should be called
ID: 3623396 • Letter: C
Question
create a structure called time.its three members ,all types int,should be called hours,minutes,and seconds.write a program that prompts the user to enter a time value in hours,minutes,and seconds.this can be in 12:59;59 format,or each number can be entered at a separate prompt("enter hours:",and so forth).the program should then store the time in a variable of type struct time,finally print out the total number of seconds represented by this time value:long total secs=t1.hours*3600+t1.minutes*60+t1.seconds
Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
using namespace std;
struct digital_clock {
int hours;
int minutes;
int seconds;
};
void gettime(digital_clock);
int main ()
{digital_clock time1,time2;
gettime(time1);
gettime(time2);
system("pause");
return 0;
}
void gettime(digital_clock time)
{long s;
cout<<"Enter the time: ";
cout<<"Enter hour: ";
cin>>time.hours;
cout<<"Enter minutes: ";
cin>>time.minutes;
cout<<"enter seconds: ";
cin>>time.seconds;
s=time.hours*3600+time.minutes*60+time.seconds;
cout<<"The time you entered is "<<s<<" seconds"<<endl;
time.hours=s/3600;
s%=3600;
time.minutes=s/60;
time.seconds=s%60;
cout<<"The time is: "<<setw(2)<<setfill('0')<<time.hours<<":"
<<setw(2)<<setfill('0')<<time.minutes<<":"
<<setw(2)<<setfill('0')<<time.seconds<<endl<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.