Jump to content

How to compute time in Turbo C 2.0 using time.h

- - - - -

  • Please log in to reply
7 replies to this topic

#1
madmhan84

madmhan84

    Newbie

  • Members
  • PipPip
  • 15 posts
Good day Sir/Ma'am,

Just want to ask if you can help me with this one, and "Please sir/ma'am can you provide me a sample code" on how to do this in C language:


If an employee input a data like this:
--------------------------------------------------
Enter Time-in: 08:00
Enter Time-out: 17:01
Lunch Break: 1 hour

/* 9 hrs. in total deducted by 1 hour lunch break = 8 hours*/

Total No. of Working Hours:8 hours
--------------------------------------------------

How will i do this?

Thanks a lot....

Edited by madmhan84, 04 April 2011 - 01:28 AM.


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,718 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Use scanf to get the times as separate hours and minutes. Then multiply hours by 60, add the minutes to it, do your math, and convert the time back into hours.
sudo rm -rf /

#3
madmhan84

madmhan84

    Newbie

  • Members
  • PipPip
  • 15 posts
Sir thanks for your kind reply, but can you show me how... can you make a sample code on how to do that? thanks a lot sir...

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,718 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
This seems like homework. We'll gladly help, but we won't do it for you. Try it, and if it doesn't work then post your next question.
sudo rm -rf /

#5
madmhan84

madmhan84

    Newbie

  • Members
  • PipPip
  • 15 posts
Sir i tried this one:

#include<time.h>

#include<stdio.h>

#include<conio.h>


main()

{

time_t start, end, total;


clrscr();

printf("Enter Time-in: ");

scanf("\n%s", &start);


printf("Enter Time-out: ");

scanf("\n%s", &end);


total = difftime(end,start);


printf("The total working hours is: %s ", total);


}


I get this WARNING: Function should return a value
and it doesn't give me the total

Edited by dargueta, 05 April 2011 - 11:55 PM.
Please use code tags next time.


#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,718 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
main() should always return a value, like this:


/* includes go here */

int main()

{

    /* put your code here */

    return 0;

}


sudo rm -rf /

#7
madmhan84

madmhan84

    Newbie

  • Members
  • PipPip
  • 15 posts
Sir, i still get the same Warning.... Function should return a value and my code doesn't show the total of working hours? what is the problem of my code? thanks in advance

#8
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,718 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Okay, another problem: you can't use the %s specifier in printf or scanf for time_t. That's a long integer. You're going to have to do what I outlined above.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users