Who's Older Code in C language #include #include "person.h" Day get_date(void); int older(Person *p1, Person *p2); int main() { Person p1, p2; p1.name = "Jay Vince"; p2.name = "Faith"; p1.bday = get_date(); p2.bday = get_date(); int old = older(&p1, &p2); if (old == -1) { printf("%s is older", p1.name); } else if (old == 1) { printf("%s is older", p2.name); } else { printf("Both are the same"); } return 0; } Day get_date() { printf("Enter the month (Jan=1, ..., Dec=12): "); Month month; scanf("%d", &month); printf("Enter the day: "); int date; scanf("%d", &date); printf("Enter the year: "); int year; scanf("%d", &year); Day today = { month, date, year}; return today; } // Returns -1 is p1 is older, 1 is p2 is older, 0 if both the same age int older(Person *p1, Person *p2) { return 0; } refer to pic for instructions
Who's Older
Code in C language
#include <stdio.h>
#include "person.h"
Day get_date(void);
int older(Person *p1, Person *p2);
int main() {
Person p1, p2;
p1.name = "Jay Vince";
p2.name = "Faith";
p1.bday = get_date();
p2.bday = get_date();
int old = older(&p1, &p2);
if (old == -1) {
printf("%s is older", p1.name);
} else if (old == 1) {
printf("%s is older", p2.name);
} else {
printf("Both are the same");
}
return 0;
}
Day get_date() {
printf("Enter the month (Jan=1, ..., Dec=12): ");
Month month;
scanf("%d", &month);
printf("Enter the day: ");
int date;
scanf("%d", &date);
printf("Enter the year: ");
int year;
scanf("%d", &year);
Day today = { month, date, year};
return today;
}
// Returns -1 is p1 is older, 1 is p2 is older, 0 if both the same age
int older(Person *p1, Person *p2) {
return 0;
}
refer to pic for instructions
Step by step
Solved in 3 steps with 5 images