"4 Million Seconds from Now" (SOLUTION)

Challenge: Write a program that will tell you what the date (4-30-2015 format is fine) will be in 4 million seconds. (One hint: tm_mon=0 means January, so be sure to add 1. Also, include the <time.h> header at the start of your program.)


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

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

struct tm futureTime;
long futureSeconds = time(NULL) + 4000000;
localtime_r(&futureSeconds, &futureTime);

futureTime.tm_mon++;  //  'Add 1' to adjust for base-zero of tm_mon
futureTime.tm_year += 1900;  //  Account for 'years since 1900' to format proper year output

printf("The date will be %d/%d/%d after four million seconds (or %ld seconds from the year 1970).\n", futureTime.tm_mon, futureTime.tm_mday, futureTime.tm_year, futureSeconds);

return 0;