Question : C++ Struct Storing Time,Calculating Elapse time

I have this struct, that stores in the starting time and ending time. then it should calculate the elapse time.

then it should display both times, and the elapse time.

i keep getting an output for start time  -18894048 .

Also i try putting in a input validation for the time, and i keep getting  TimeClock <= int" is illegal.

i try doing something like  

cout<<enter start time: ";
cin>> temp
if (temp <= 0 && temp <=2359)
 {
    temp.StartTime;
 } else{
   cout<<Time cannot be negative or over 2359";
  get_elapse(CL);
}

but no luck with it.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
#include <iostream>
#include <string>
using namespace std;

struct TimeClock
{ 
  int StartTime;
  int EndTime;
  int Elapse;
};

//prototype
TImeClock get_elapse(TimeClock CL);


int main()
{
 TimeClock CL;
 get_elapse(CL);
 cout<<"Start Time:"<<CL.StartTime<<endl;
 cout<<"Start Time: "<<CL.EndTime<<endl;
 cout<<"Elapse Time: "<<CL.Elapse<<endl;


return 0;
}


TimeClock get_elapse(TimeClock CL)
{
  TimeClock temp;

  cout<< "Enter Starting time in military time: " // 1500
  cin>>temp.StartTime;
  cout<<endl;
  cout<< "Enter Ending time in military time: " // 2300
  cin>>temp.EndTime;

//Calculating Elapse Time
  temp.Elapse =  temp.EndTime - temp.StartTime;

  return temp;
}

Answer : C++ Struct Storing Time,Calculating Elapse time

Dates don't have formats, only the string representations of the dates do

If you mean you want a DATE value with the time component truncated to 00:00:00 then try


TRUNC(sysdate)

you can't remove the time portion of a date,  some strings formats don't display 00:00:00 though
Random Solutions  
 
programming4us programming4us