In: Computer Science
Given the following int variables which represent a date,
int day; // 0-6 for Sunday-Saturday int month; // 1-12 for January-December int date; // 1-31 int year; // like 2020
Define the function
void tomorrow(int& day, int& month, int& date, int& year);
which updates the variables to represent the next day. Test in main().
Greetings!!
Code:
#include <stdio.h>
#include <stdlib.h>
void tomorrow(int *, int *, int *, int *);
int main()
{
int day,month,date,year;
printf("Please enter the day 0-6:\n");
scanf("%d",&day);
printf("Please enter the month 1-12:\n");
scanf("%d",&month);
printf("Please enter the date 1-31:\n");
scanf("%d",&date);
printf("Please enter the year:\n");
scanf("%d",&year);
tomorrow(&day,&month,&date,&year); //calling
function
return 0;
}
void tomorrow(int *dy, int *m, int *dt, int *y)
{
int day,month,date,year;
if(*m==2) //if february
{
if(*dt<29)
{
*dt=*dt+1;
*dy=(*dy%6)+1;
}
else
{
if(*dt==29) //if the date is 29
{
if(*y%4==0)
{
*dt=1;
*m=3;
*dy=(*dy%6)+1;
}
else
{
printf("\n\n\nSorry! Invalid year!!\n\n\n");
exit(0);
}
}
else
{
printf("\n\n\nSorry! Invalid date!!\n\n\n");
exit(0);
}
}
}
else if((*m==4)|(*m==6)|(*m==9)|(*m==11))
{
if(*dt==31)
{
printf("\n\n\nSorry! Invalid date!!\n\n\n");
exit(0);
}
else if(*dt==30)
{
*dt=1;
*m=*m+1;
*dy=(*dy%6)+1;
}
else
{
*dt=*dt+1;
*dy=(*dy%6)+1;
}
}
else if(*m==12)
{
if(*dt==31)
{
*dt=1;
*m=(*m%12)+1;
*dy=(*dy%6)+1;
*y=*y+1;
}
else
{
*dt=*dt+1;
*dy=(*dy%6)+1;
}
}
else
{
*dt=*dt+1;
*dy=(*dy%6)+1;
}
printf("\nTomorrow:\n\n day=%d\n month=%d\n date=%d\n
year=%d\n",*dy,*m,*dt,*y);
}
Output screenshots:
Case 1:
Case 2:
Case 3:
Case 4:
Case 5:
Case 6:
Hope this helps