help with program

how can i get this program to tell me the difference in the date entered to todays date in hours

#include <stdio.h>
#include <time.h>
#include <iostream>

using namespace std;
int main ()
{
time_t rawtime;
struct tm * timeinfo;
int year, month ,day;
char * weekday[] = { "Sunday", "Monday",
"Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};

/* prompt user for date */
printf ("Enter year: "); scanf ("%d",&year);
printf ("Enter month: "); scanf ("%d",&month);
printf ("Enter day: "); scanf ("%d",&day);

/* get current timeinfo and modify it to the user's choice */
time ( &rawtime );
timeinfo = localtime ( &rawtime );
timeinfo->tm_year = year - 1900;
timeinfo->tm_mon = month - 1;
timeinfo->tm_mday = day;

/* call mktime: timeinfo->tm_wday will be set */
mktime ( timeinfo );

printf ("That day is a %s.\n", weekday[timeinfo->tm_wday]);
system ("pause");
return 0;
}
Last edited on
Have you looked at the fields in your timeinfo variable?
seriouly im just beginning this stuff so im not sure what you mean by fields.. sorry but im guessing no
timeinfo is a record with a number of fields. You access them in:
1
2
3
4
timeinfo = localtime ( &rawtime );
timeinfo->tm_year = year - 1900;
timeinfo->tm_mon = month - 1;
timeinfo->tm_mday = day;
Have you looked at all of them? You'll find there's enough information to deduce the time difference.
i havent and im not sure how to go about doing that...
This page shows what ought to be in time.h and shows the members of struct tm.
http://pubs.opengroup.org/onlinepubs/007908799/xsh/time.h.html
Topic archived. No new replies allowed.