Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //Calculates the exact age of sombody or somthing
- //currently assumes leap years do not exsist.
- int main() {
- //finds date of birth and current date
- int bm, bd, by;
- printf("Enter your Date of Birth\nMM/DD/YYYY\n");
- scanf("%d/%d/%d",&bm,&bd,&by);
- int cm, cd, cy;
- printf("Enter the current date\n");
- scanf("%d/%d/%d",&cm,&cd,&cy);
- // month type
- int mon31[7]={1,2,4,6,8,9,11};
- int mon30[4]={5,7,10,12};
- int feb=3;
- // calculates the age
- int mwrap = bm+cm;
- int dwrap = bd+cd;
- //year
- int year;
- if ( cy >= by ) {
- year = cy-by;
- }
- else {
- printf("you are not alive dipshit\n");
- return 0;
- }
- //month
- int month;
- if ( cm >= bm ) {
- month = cm-bm;
- }
- else{
- if ( year == 0 ) {
- printf("you are not alive dipshit\n");
- return 0;
- }
- else {
- int month = 12-mwrap;
- }
- }
- //day
- int day;
- int days;
- if ( cd >= bd) {
- day = cd-bd;
- }
- else {
- if ( month == 0) {
- printf("you are not alive dipshit\n");
- return 0;
- }
- else{
- if ( cm == mon31[7] ) {
- days = 31;
- }
- if ( cm == mon30[4] ) {
- days = 30;
- }
- if ( cm == feb ) {
- days = 28;
- }
- day = days-dwrap;
- }
- }
- printf("%d years, %d months, and %d days",year,month,day);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement