# Thread: C Program that output the very next date after Input a date

1. ## C Program that output the very next date after Input a date

It's my second week of learning C programming. So, don't laugh at me . I have figured out the algorithm of the problem, but after coding it's not working. Would you please tell me where's the problem?

Code:
```#include<stdio.h>
int main()
{
int d, m, y, nd, nm, ny;
printf("Enter the year: ");
scanf("%d", &y);
printf("\nEnter the month: ");
scanf("%d", &m);
printf("\nEnter the date: ");
scanf("%d", &d);
printf("\nSo, your desired date is: %d/%d/%d", d, m, y);
if (m%2!=0 && m<=7)
{
if (d==31)
{
nd=1;
nm=m+1;
ny=y;
}
}
else if (m%2==0 && 8<=m<=12)
{
if (d==31)
{
nd=1;
nm=m+1;
ny=y;
}
}
else if (m%2==0 && 4<=m<=6)
{
if (d==30)
{
nd=1;
nm=m=1;
ny=y;
}
}
else if (m%2!=0 && 9<=m<=11)
{
if (d==30)
{
nd=1;
nm=m+1;
ny=y;
}
}
else if (m==2 && y%4==0)
{
if (d==29)
{
nd=1;
nm=m+1;
ny=y;
}
}
else if (m==2 && y%4!=0)
{
if (d==28)
{
nd=1;
nm=m+1;
ny=y;
}
}
else if (m==12 && d==31)
{
nd=1;
nm=1;
ny=y+1;
}
else
{
nd=d+1;
nm=m;
ny=y;
}
printf("\n\nThe next date of your desired date is:\t%d/%d/%d\n", nm, nm, ny);
}```

2. Can you tell us what the problem is?

Edit1: The below code does NOT do what you think it does!
Code:
`8<=m<=12`
Likely want

Code:
`(8<=m && m<=12)`
Tim S.

3. Originally Posted by stahta01
Can you tell us what the problem is?

Edit1: The below code does NOT do what you think it does!
Code:
`8<=m<=12`
Likely want

Code:
`(8<=m && m<=12)`
Tim S.
Thank you for your help . The problem is: "C Program that output the very next date after Input a date" According to your comment I changed the program a little bit. But still not working

Code:
```#include<stdio.h>int main()
{
int d, m, y, nd, nm, ny;
printf("Enter the year: ");
scanf("%d", &y);
printf("\nEnter the month: ");
scanf("%d", &m);
printf("\nEnter the date: ");
scanf("%d", &d);
printf("\nSo, your desired date is: %d/%d/%d", d, m, y);
if (m%2!=0 && m>=1 && m<=7 && d==31)
{
nd=1;
nm=m+1;
ny=y;
}
else if (m%2==0 && m>=8 && m<=12 && d==31)
{
nd=1;
nm=m+1;
ny=y;
}
else if (m%2==0 && m>=4 && m<=6 && d==30)
{
nd=1;
nm=m=1;
ny=y;
}
else if (m%2!=0 && m>=9 && m<=11 && d==30)
{
nd=1;
nm=m+1;
ny=y;
}
else if (m==2 && y%4==0 && d==29)
{
nd=1;
nm=m+1;
ny=y;
}
else if (m==2 && y%4!=0, d==28)
{
nd=1;
nm=m+1;
ny=y;
}
else if (m==12 && d==31)
{
nd=1;
nm=1;
ny=y+1;
}
else
{
nd=d+1;
nm=m;
ny=y;
}
printf("\n\nThe next date of your desired date is:\t%d/%d/%d\n", nm, nm, ny);
}```

4. Why isn't it working?

Jim

5. If you are NOT going to tell us the problem with your program; then go away and never post on the Internet again.

Edit: You have some reason to believe your program is NOT correct; TELL US the reason!!!

Tim S.

6. Guys, please try to understand. It's not working as the output is not as it should be, for example if input is 23/1/2013 output is 1/1/2013. But it should be 24/1/2013. Same problem for every input

7. Why are you playing with the month in most of your if statements. You should first just add one to the day, if that is less than 29 you should be done, after all, all months have at least 28 days.

Also in your last print statement you seem to be printing the month twice, don't you want to print the day?
Code:
`  printf("\n\nThe next date of your desired date is:\t%d/%d/%d\n", nm, nm, ny);`
Jim

8. Thanks Jims. Now works. You are the man