Chapter # 4: Exercise Pages# 159 Question Number 9
Book Object Oriented Programming by Robert Lafore
Code:
#include <iostream>
using namespace std;
struct time // a strcuture time defined
{
int hours; // hours in time
int minutes; // minutes in time
int seconds; // seconds in time
};
int main()
{
int totalsecs;
time var_time;
cout<<"Please enter the hours = ";
cin>>var_time.hours;
cout<<"Please enter the mintues = ";
cin>>var_time.minutes;
cout<<"Please enter the seconds = ";
cin>>var_time.seconds;
totalsecs = var_time.hours*3600+var_time.minutes*60+var_time.seconds;
cout<<"total sconds of the given time are calculated as = "<<totalsecs<<endl;
return 0;
}
Here is the result: