Find a Remaining Day

 #include <stdio.h>

#include <time.h>

int main() {
    struct tm userDate;
    time_t currentTime, userTime;
    double secondsRemaining, daysRemaining;

    // Get the current time
    time(&currentTime);

    // Prompt the user to enter a date
    printf("Enter a date (YYYY-MM-DD): ");
    scanf("%d-%d-%d", &userDate.tm_year, &userDate.tm_mon, &userDate.tm_mday);

    // Adjust the year and month values
    userDate.tm_year -= 1900; // Years since 1900
    userDate.tm_mon -= 1;     // Month (0-11)

    // Convert the user-specified date to a time_t value
    userTime = mktime(&userDate);

    // Calculate the remaining time in seconds
    secondsRemaining = difftime(userTime, currentTime);

    // Calculate the remaining days
    daysRemaining = secondsRemaining / (60 * 60 * 24);

    if (daysRemaining < 0) {
        printf("The specified date is in the past.\n");
    } else {
        printf("Remaining days: %.0lf\n", daysRemaining);
    }

    return 0;
}

Comments

Popular posts from this blog

History of Computer

Introduction to Computer

Computer Generation