Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Simplify the following program using loops, scanf, etc. This program can choose

ID: 3639267 • Letter: S

Question

Simplify the following program using loops, scanf, etc.

This program can choose earliest date from a number of dates.
The user will enter 0/0/0 to indicate that no more dates will be entered:

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int month,day,year;
int monthNew,dayNew,yearNew;
printf("Enter a date (mm/dd/yyyy): ");
scanf("%d /%d /%d", &month, &day, &year);
monthNew=month;
dayNew=day;
yearNew=year;
while(month!=0&&day!=0&&year!= 0)
{if(year<yearNew)
{monthNew=month;
dayNew=day;
yearNew=year;
}
else if(year==yearNew) //possible error here
if(month<monthNew)
{monthNew=month;
dayNew=day;
}
else if(month==month)
if(day<dayNew)
{dayNew=day;
}
printf("Enter a date (mm/dd/yyyy): ");
scanf("%d /%d /%d", &month, &day, &year);
}
printf("%d/%d/%02d is the earliest date",monthNew,dayNew,yearNew);
return 0;
}

Explanation / Answer

you forgot a brace here else if(year==yearNew) //possible error here { //--->here if(month
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote