Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- bool CheckBisestile(int Y);
- bool CheckData(int Y, int M, int D);
- int main()
- {
- int Y, M, D;
- do
- {
- printf("Inserisci l'anno.\n");
- scanf("%d", &Y);
- printf("Inserisci il mese.\n");
- scanf("%d", &M);
- printf("Inserisci il giorno.\n");
- scanf("%d", &D);
- }
- while(CheckData(Y, M, D) == false);
- return 0;
- }
- bool CheckData(int Y, int M, int D)
- {
- int DOM;
- if(Y < 0 || Y > 3000) return false;
- switch(M)
- {
- case 1-3-5-7-8-10-12: DOM = 31;
- case 4-6-9-11: DOM = 30;
- case 2:
- {
- if(CheckBisestile(Y) == true) DOM = 29;
- else DOM = 28;
- }
- default: return false;
- }
- if(D < 1 || D > DOM) return false;
- printf("La data รจ corretta!\n");
- return true;
- }
- bool CheckBisestile(int Y)
- {
- if ((Y % 4) == 0 && (Y % 100) != 0 || (Y % 400) == 0) return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement