Hi everyone!

This is the code that I have made, however, when I enter a date for example if I type : 12/12/2012 then the date for tomorrow displays a list of dates. I am unsure how to get it to only display the date of tomorrow.

include <stdio.h>

int main (int argc, char *argv[]) {

int dd;
int mm;
int yyyy;
int n = 3;

printf("Enter date in format dd/mm/yyyy: \n");
n = scanf("%d/%d/%d", &dd, &mm, &yyyy);
printf("Date read: %d/%d/%d\n", dd, mm, yyyy);

if (n==3) {

if (dd==31 && mm==1) {
              printf("Tomorrow: 01/02/%d\n", yyyy);
             }
else if (dd==28 && mm==2 && yyyy%4==0) {
                    printf("Tomorrow: 29/02/%d\n", yyyy);
                    }

else if (dd==29 && mm==2 && yyyy%4==0) {
                    printf("Tomorrow: 01/03/%d\n", yyyy);
                    }

else if (dd==28 && mm==2 && yyyy%4!=0) {
                    printf("Tomorrow: 01/03/%d\n", yyyy);
                    }

else if (dd==31 && mm==3) {
              printf("Tomorrow: 01/04/%d\n", yyyy);
             }

else if (dd==30 && mm==4) {
              printf("Tomorrow: 01/05/%d\n", yyyy);
             }

else if (dd==31 && mm==5) {
              printf("Tomorrow: 01/06/%d\n", yyyy);
             }

else if (dd==30 && mm==6) {
              printf("Tomorrow: 01/07/%d\n", yyyy);
             }

else if (dd==31 && mm==7) {
              printf("Tomorrow: 01/08/%d\n", yyyy);
             }

else if (dd==31 && mm==8) {
              printf("Tomorrow: 01/09/%d\n", yyyy);
             }

else if (dd==30 && mm==9) {
              printf("Tomorrow: 01/10/%d\n", yyyy);
             }

else if (dd==31 && mm==10) {
              printf("Tomorrow: 01/11/%d\n", yyyy);
             }

else if (dd==30 && mm==11) {
              printf("Tomorrow: 01/12/%d\n", yyyy);
             }

else if (dd==31 && mm==12) {
                    yyyy = yyyy + 1;
                printf("Tomorrow: 01/01/%d\n", yyyy);
             }

//30 day months 

else if (dd>0 && dd<30 && (mm==4 || mm==6 || mm==9 || mm==11)) {
                                (dd = dd + 1); {
                                printf("Tomorrow: %d/%d/%d\n", dd, mm, yyyy);
                                   }
                            }
//31 day months

else if (dd>0 && dd<31 && (mm==1 || mm==2 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12)) {
                                                (dd = dd + 1); {
                                             printf("Tomorrow: %d/%d/%d\n", dd, mm, yyyy);
}                                  }
}

else if (n!=3) {
        return 0;
        }

return 0;

}

Thank you for any help you can offer

12/12/2012 then the date for tomorrow displays a list of dates

could you post a sample output of the code
I'm unable to duplicate the problem since I got only one date for the output when I entered 12/12/2012

This is the output:

Enter date in format dd/mm/yyy:
12/12/2012
Date: read: 12/12/2012
Tomorrow: 12/12/2012
Tomorrow: 13/12/2012
Tomorrow: 14/12/2012
Tomorrow: 15/12/2012
Tomorrow: 16/12/2012
Tomorrow: 17/12/2012
Tomorrow: 18/12/2012
Tomorrow: 19/12/2012
Tomorrow: 20/12/2012
Tomorrow: 21/12/2012
Tomorrow: 22/12/2012
Tomorrow: 23/12/2012
Tomorrow: 24/12/2012
Tomorrow: 25/12/2012
Tomorrow: 26/12/2012
Tomorrow: 27/12/2012
Tomorrow: 28/12/2012
Tomorrow: 29/12/2012
Tomorrow: 30/12/2012

Another example:
Enter date in format dd/mm/yyy:
23/05/2000
Date: read: 23/05/2000
Tomorrow: 23/05/2000
Tomorrow: 24/05/2000
Tomorrow: 25/05/2000
Tomorrow: 26/05/2000
Tomorrow: 27/05/2000
Tomorrow: 28/05/2000
Tomorrow: 29/05/2000
Tomorrow: 30/05/2000

Did you post the whole code? I don't see any loop that will print the output again
I tried the program with linux gcc and windows cgwin compiler and got only one output...

I tried it again now and it is working properly. I'm not quite sure what I had wrong earlier to get the unusual output.
Thank you very much for your help zeroliken

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.