Write a main() that asks a user for the birthdays of two people (storing them in
ID: 1798532 • Letter: W
Question
Write a main() that asks a user for the birthdays of two people (storing them in two structs that have been declared in main), then uses the function written above to determine which one is youngerExplanation / Answer
#include #include int main() { char tempA[20],tempB[20]; struct a { int day,month,year; }a,b; printf("enter 1st person's birthday(mm/dd/yyyy)");//prompting user to enter his birthday scanf("%s",tempA);//storing the value in an array a.day=tempA[0]*10+tempA[1]; a.month=tempA[3]*10+tempA[4]; //removing '/' a.year=tempA[6]*1000+tempA[7]*100+tempA[8]*10+tempA[9]; printf("enter 2nd person's birthday(mm/dd/yyyy)"); scanf("%s",tempB); b.day=tempB[0]*10+tempB[1]; b.month=tempB[3]*10+tempB[4]; b.year=tempB[6]*1000+tempB[7]*100+tempB[8]*10+tempB[9]; if(((a.year)>(b.year))|| ((a.year==b.year)&&(a.month>b.month)) || (((a.year==b.year)&&(a.month>b.month))&&(a.day>b.day))) printf("2nd person is younger"); else if(((a.year>(b.year))|| ((a.year==b.year)&&(a.month>b.month)) || (((a.year==b.year)&&(a.month>b.month))&&(a.day>b.day)))) printf("1st person is younger"); else printf("both are of same age"); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.