Final answer:
To solve this problem, you need to write a C program that takes the current date as input and then uses a loop to read the name and birth date of a person. The program should calculate the person's age in terms of days, months, and years and display the result.
Step-by-step explanation:
To solve this problem, you need to write a C program that takes the current date as input and then uses a loop to read the name and birth date of a person. The program should calculate the person's age in terms of days, months, and years and display the result.
You can use the assumptions provided in the question to determine the number of days in each month. For example, if the current month is April (month number 4), you can set the number of days to 30.
Here's a basic example of how the program might look:
#include <stdio.h>
#include <time.h>
int main() {
int currentDay, currentMonth, currentYear;
time_t t = time(NULL);
struct tm tm = *localtime(&t);
// Read current date
printf("Enter current date (day month year): ");
scanf("%d %d %d", ¤tDay, ¤tMonth, ¤tYear);
// Read names and birth dates
printf("Enter names and birth dates (day month year), enter EOF to stop: ");
while (scanf("%s %d %d %d", name, &day, &month, &year) == 4) {
// Calculate age
int ageYears = currentYear - year;
int ageMonths = currentMonth - month;
int ageDays = currentDay - day;
// Adjust for negative age
if (ageDays < 0) {
ageMonths--;
ageDays += 30;
}
if (ageMonths < 0) {
ageYears--;
ageMonths += 12;
}
// Display result
printf("%s: %d years, %d months, %d days\\", name, ageYears, ageMonths, ageDays);
}
return 0;
}