Question: Instructions: Write a program that asks the user for a date in the format mm/dd/yyyy, using a custom struct to store the date information entered

Instructions: Write a program that asks the user for a date in the format mm/dd/yyyy, using a custom struct to store the date information entered in memory. The program should call a custom function that adds seven days to the user's date, passing in the data in and out of the custom function using the custom struct for the dates. The program should then print out the original date entered and the date one week later. As always, be sure to format your C code correctly and include meaningful comments to explain what the code does and how it works.

code previously provided in response to same quesetion:

#include

struct date//structure declaration { int day,month,year;//date,month,year; }; void addseven(struct date d)//function which adds 7 to present date and prints to stdout { int m[] ={31,28,31,30,31,30,31,31,30,31,30,31};//array to keep track of days in month d.day = d.day+7;//incrementing days if(d.day>m[d.month-1])//if exceeds monthly days limit then { int k=d.day-m[d.month-1]; d.day = k; d.month = d.month+1;//increment month count if(d.month>12)//if month exceeded 12 { d.year =d.year+1;//incrementing year d.month=1; } } //printing result printf("Date after one week : %d/%d/%d ",d.month,d.day,d.year); }

int main() { struct date present;//present date char c[10]; printf("Enter date in format(mm/dd/yyyy) :"); scanf("%s",c);//reading as string int i=0,k=0,l,s=0; for(i=0;c[i]!='\0';i++)//converting to integer... and storing in structure { if(c[i]=='/' && k==0) { k=1; present.month = s;//storing month s=0; } else if (c[i]=='/' && k==1) { k=2; present.day = s;//storing day s=0; } else { l = (int)c[i]-48; s =s*10+l;} } present.year =s;//storing year //printing present date printf("present date : %d/%d/%d ",present.month,present.day,present.year); addseven(present);//function calling return 0; }

******The Issue******* I have reached the final steps whereas I can enter the date, however the present date and date after 7 days produce the incorrect year. The MM/DD is correct: Enter Date:10/19/2017 Present Date:10/19/20141 Future Date (1 week):10/26/20141

Please assist. Using a different compiler (as prev suggested in response to this same issue) is NOT an option, this is in c::b

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!