Sunday, 8 April 2018

Create a structure called time. Its three members, all type 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, and finally print out the total number of seconds represented by this time value: long totalsecs = t1.hours*3600 + t1.minutes*60 + t1.seconds.

using namespace std;
#include<iostream>
#include<conio.h>
struct time{
int hours,mint,sec;
};
int main()
{
time t;
int total_sec;
cout<<"Enter the Hours:";
cin>>t.hours;
cout<<"Enter the minutes:";
cin>>t.mint;
cout<<"Enter seconds:";
cin>>t.sec;
cout<<"Your entered time is "<<t.hours<<":"<<t.mint<<":"<<t.sec<<endl;
total_sec=t.hours*3600+t.mint*60+t.sec;
cout<<"Total second in your entered time is: "<<total_sec;

}

No comments:

Post a Comment