Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int day = 0, month = 0, year = 0, dayLimit = 31;
- printf("Input the date (syntax: dd.mm.yyyy (example: 08.12.2005) (year should be lower or equals to 2017)): ");
- scanf("%d.%d.%d", &day, &month, &year);
- getchar(); //clean buffer
- if ((day < 1 || day > 31) || (month < 1 || month > 12) || (year < 1 || year > 2017)) //check if wrong input (check 1/2)
- {
- printf("[a] wrong input.\n");
- return -1; //stop program
- }
- switch(month) //check if the number of days correct (according the month, for example: in february - 28 days, and not 29) (check 2/2)
- {
- case 2: //check if the month equals to february, and if the days don't greater than 28
- if (day > 28)
- {
- printf("[b] wrong input.\n");
- return -1; //stop program
- }
- dayLimit = 28; //setting the limit of the days in this month to 28
- break;
- case 4: //check if the month equals to: april(4), june(6), september(9), november(11), and if the days don't greater than 30
- case 6:
- case 9:
- case 11:
- if (day > 30)
- {
- printf("[b] wrong input.\n");
- return -1; //stop program
- }
- dayLimit = 30; //setting the limit of the days in this month to 30
- break;
- }
- day++; //adding one day
- if (day > dayLimit) //checks if the day passed the limit (according the months)
- {
- month++; //increase month by 1
- day = 1;
- if (month > 12) //checks if the month passed the max limit (12)
- {
- year++; //increase year by 1
- month = 1;
- }
- }
- printf("The next day will be: %02d.%02d.%04d\n", day, month, year);
- //02d -> if the days lower than 2 numbers it will add 0 to the beginning (days: 2, output: 02)
- //04d -> if the year lower than 4 numbers it will add zeros to the beginning (year: 10, output: 0010)
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement