|
-
September 1st, 2009, 01:27 AM
#1
C++ Date and Time
I need help please. I am new to C++. I want to create a program that would compute the weekly salary of the employees. The program would accept TIME-IN and TIME-OUT inputs then get the total hours for the day. The time format is in military time (e.g. 13:00 is 1:30 pm). I also want to get the total hours for the week.
Inputs: (1234, Josef Alarka, 380.00, 08:00, 17:01, and June 11-15, 2009)
Employee Number: 12345
Name: Josef Alarka
Salary Rate: 380.00
Time-In for Monday: 08:00
Time-Out for Monday: 17:01
.
.time in, time-out from monday to friday.
.
Time-In for Friday: 08:00
Time-Out for Friday: 17:01
Coverage Date: June 11-15, 2009
Outputs:
************************
Employee Number: 1234
Name: Josef Alarka
Salary Rate: Php 380.00 (with currency format. still i don't know how to format this)
************************
Date Covered: June 11-15, 2009
Total Number of Hours Worked: 40 hrs.
Net Income: Php 1900.00
************************
Any help is very much appreciated. Thank you very much.
-
September 1st, 2009, 02:44 AM
#2
Re: C++ Date and Time
 Originally Posted by josefalarka
The time format is in military time (e.g. 13:00 is 1:30 pm).
1- You are confusing "Military Time" and "24h date format".
2- 13:00 is NOT 1:30pm. it is 1:00pm. For example, 21:35 is 9h35pm.
anyways, after this short rant, you should know that c++ has no built in time/date classes.
You can either create your own (HIGHLY NOT RECOMMENDED), or look for a third party one. Boost probably has something, but I'm not sure.
-
September 1st, 2009, 12:48 PM
#3
Re: C++ Date and Time
boost has a large date-time lib. it can be a bit difficult to find what you want if its the first time using it.
-
September 1st, 2009, 03:07 PM
#4
Re: C++ Date and Time
wxWidgets also has a nice date/time library.
Actually, C++ does have a time structure... kind of. It's a C structure, so it's not recommended that you use in in your C++ code, but you can. It's called tm and it's in time.h
-
September 2nd, 2009, 04:51 AM
#5
Re: C++ Date and Time
Still confused how to input the TIME-IN and TIME-OUT. My sample code below;
#include<iostream.h>
#include<time.h>
int main()
{
time_t T_in;
time_t T_out;
time_t T_dif;
cout<<"TIME-IN: ";
cin>>T_in;
cout<<"TIME-OUT: ";
cin>>T_out;
T_dif = T_out - T_in;
cout<<"The total hours worked is: "<<T_dif<<endl;
return 0;
}
OUTPUT:
TIME-IN: 7:30
TIME-OUT: The total hours worked is: -7
I think the only value stored in T_in after I entered 7:30, is just 7. How to resolved this? Please help.
-
September 2nd, 2009, 07:25 AM
#6
Re: C++ Date and Time
You have to check the validity of the input. E.g.
Code:
if (cin >> T_in) {
// valid input
}
else {
// invalid input, need to flush input buffer
}
I'm not sure what the input format for time_t is.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|