My Solution to the Future Time Challenge


#1

Hi guys,

Im new to coding. This is what I came up with. Any feedback will be appreciated. Thank you.

[code]#include <stdio.h>
#include <time.h>

int main(int argc, const char * argv[])
{

// Create variable to hold the number of seconds that will be added to today's date
float futureseconds = 4000000;

//Get today's date in seconds
long secssince1970 = time(NULL);

//Add 4 million seconds to today's date
long futuretime = futureseconds+ secssince1970;

//Define struct tm

struct tm l ;

//use localtime_r() to read future date
localtime_r (&futuretime, &l) ;

printf("In 4,000,000 million seconds the date will be %d-%d-%d\n", l.tm_mon + 1, l.tm_mday, l.tm_year +1900);



return 0;

}

[/code]


#2

here is my solution, I did the math and it gives the date 46 days from today

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

int main(int argc, const char * argv[]) {

long secondsSince1970 = time(NULL);
printf("It has been %ld seconds since 1970\n", secondsSince1970); //kept this in but not needed
struct tm then;
secondsSince1970 = secondsSince1970 + 4000000;
localtime_r(&secondsSince1970, &then);
printf("The date in 4 million seconds will be: %d - %d - %d.\n", then.tm_mon +1, then.tm_mday, then.tm_year +1900);

return 0;

}

hope this helps