elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Re: calcular funcion edad con funcion fecha de nacimiento en: 28 Septiembre 2015, 00:00 am
GRACIAS POR EL CODIGO PERO ME AYUDAN UTILIZANDO COUT Y CIN POR FAVOR. GRACIAS

Una solución a esto seria

Código
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. typedef struct
  5. {
  6.    int dia;
  7.    int mes;
  8.    int año;
  9. } fecha;
  10.  
  11. int calcular_edad(fecha datos)
  12. {
  13.    time_t t = time(NULL);
  14.    struct tm tm = *localtime(&t);
  15.  
  16.    int a = ((tm.tm_year + 1900) * 100 + tm.tm_mon + 1) * 100 + tm.tm_mday;
  17.    int b = (datos.año * 100 + datos.mes) * 100 + datos.dia;
  18.  
  19.    return (a - b) / 10000;
  20. }
  21.  
  22. int main(void)
  23. {
  24.    fecha datos;
  25.  
  26.    printf("\nIngrese Fecha de Nacimiento dd/mm/aaaa: ");
  27.    scanf("%d/%d/%d",&datos.dia,&datos.mes, &datos.año);
  28.  
  29.    printf("Su edad es %d\n", calcular_edad(datos));
  30.  
  31.    return(0);
  32. }
  33.  

Saludos
2  Programación / Programación C/C++ / Re: calcular funcion edad con funcion fecha de nacimiento en: 27 Septiembre 2015, 23:58 pm
#include <stdio.h>
#include <time.h>
 
typedef struct
{
    int dia;
    int mes;
    int año;
} fecha;
 
int calcular_edad(fecha datos)
{
    time_t t = time(NULL);
    struct tm tm = *localtime(&t);
 
    int a = ((tm.tm_year + 1900) * 100 + tm.tm_mon + 1) * 100 + tm.tm_mday;
    int b = (datos.año * 100 + datos.mes) * 100 + datos.dia;
 
    return (a - b) / 10000;
}
 
int main(void)
{
    fecha datos;
 
    printf("\nIngrese Fecha de Nacimiento dd/mm/aaaa: ");
    scanf("%d/%d/%d",&datos.dia,&datos.mes, &datos.año);
 
    printf("Su edad es %d\n", calcular_edad(datos));
 
    return(0);
}

me gustaria que me ayudaran, este codigo sirvio pero necesito solo utilizarlo con cout y cin por favor
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines