globus243

Age Check!

Aug 23rd, 2011
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.26 KB | None | 0 0
  1. /*age check (c) By Tim Hartmann*/
  2.  
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <conio.h>
  7. #include <windows.h>
  8. #include <time.h>
  9. #include <string.h>
  10.  
  11. int main ()
  12. {
  13.     SetConsoleTitle(" Age Check! ");
  14.     SYSTEMTIME time;
  15.     GetSystemTime (&time);
  16.      
  17.     char name[20], bday[13], bjahr[5], bmonat[3], btag[3];
  18.     char *bump;
  19.  
  20.     int year = time.wYear;
  21.     int month = time.wMonth;
  22.     int day = time.wDay;
  23.     int intjahr, intmonat, inttag, alter;
  24.    
  25.  begin:  
  26.     printf("\n\n Heute ist der: %i.%i.%i \n\n",day,month,year);
  27.     printf(" Bitte ein Geburtsdatum eingeben. (tt.mm.jjjj).\n\n");
  28.    
  29.     bump=&bday;
  30.    
  31.     bday[0]='.';
  32.    
  33.     bump++;
  34.    
  35.     fgets(bump,sizeof(bday)-1, stdin);
  36.    
  37.     if(strlen(bday) < 12){
  38.         printf("\n\n ungueltiges Datum!\n\n");
  39.                
  40.         system("pause");
  41.         system("cls");
  42.         goto begin;
  43.     }
  44.    
  45.     strncpy(bjahr , &bday[7], 4);
  46.         bjahr[4] =  '\0';
  47.  
  48.     strncpy(bmonat, &bday[4], 2);
  49.         bmonat[2]=  '\0';        
  50.        
  51.     strncpy(btag  , &bday[1], 2);
  52.         btag[2]  =  '\0';
  53.                
  54.     intjahr  = atoi(bjahr) ;
  55.     intmonat = atoi(bmonat);
  56.     inttag   = atoi(btag)  ;
  57.    
  58.    
  59.     if((intjahr > year) || (intmonat > 12) || (inttag > 31)){
  60.         printf("\n\nungueltige einabe \n\n");
  61.        
  62.         getchar();
  63.         system("cls");
  64.         goto begin;
  65.        
  66.     }
  67.    
  68.     alter=year-intjahr;
  69.    
  70.     if((intmonat==month) && (inttag==day)){
  71.            printf("\n\n Happy Birtday, Ich glaube ich muss dir nicht sagen wie alt du bist oder?"
  72.                   "\n nagut, du bist %i geworden\n\n",alter);
  73.            system("pause");
  74.            system("cls");
  75.            goto begin;
  76.     }
  77.    
  78.     if((intmonat <= month) && (inttag <= day)){
  79.        
  80.          if(alter==1){
  81.          printf("\n\n Diese Person ist 1 Jahr alt\n\n\n");
  82.          
  83.          system("pause");
  84.          exit(1);
  85.                 }
  86.        
  87.         printf("\n\n Diese Person ist %i Jahre alt.\n\n",alter);
  88.        
  89.     }
  90.    
  91.     else{
  92.        
  93.        
  94.        
  95.     printf("\n\n Diese Person ist %i Jahre alt.\n\n",alter-1);
  96.     }
  97.    
  98.    
  99.     system("PAUSE");
  100.     system("cls");
  101.     goto begin;
  102.              
  103. }
Advertisement
Add Comment
Please, Sign In to add comment