#include <cstring> // en C++ equivale a string.h
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <iostream>
using namespace std;
struct Time
{
int d,m,y;
};
struct Time horalocal()
{
struct Time mt;
struct tm *local;
time_t t;
t=time(NULL);
local=localtime(&t);
mt.d=local->tm_mday;
mt.m=local->tm_mon+1;
mt.y=local->tm_year+1900;
return mt;
}
enum{ANIOS,MESES}; // tipos de valores devueltos por fechanac()
int val_dev; // almacena el tipo de valor devuelto por fechanac()
float fechanac(struct Time t)
{
struct Time h;
float year;
val_dev=ANIOS;
h=horalocal();
year=h.y-t.y;
if(year>1)
{
if(h.m < t.m)
year--;
else if(h.m == t.m && h.d < t.d)
year--;
}
else if((year>=0)&&(year<=1))
{
// calculo de los meses transcurridos
int meses=h.m-t.m;
if(year==1)
meses+=12;
if(meses<12)
{
year=meses;
val_dev=MESES;
}
}
return year;
}
void nombre()
{
system("color 75");
cout<<"nnn";
cout<<" ==========================="<<endl;
cout<<" = Programa Para ="<<endl;
cout<<" = Saber ="<<endl;
cout<<" = LA Edad ="<<endl;
cout<<" ==========================="<<endl;
cout<<" By Powered Luis Alfonso Jimenez"<<"nnnn"<<endl;
system("PAUSE");
system("cls");
}
int main()
{
char res;
do
{
nombre();
system("color 74");
struct Time fech;
cout<<"nnintroduce el dia en que naciste"<<endl;
cout<<"==================================="<<endl;
cin>>fech.d ;
cout<<"ahora el mes (un numero 1-12)"<<endl;
cout<<"==================================="<<endl;
cin>>fech.m ;
cout<<"ahora el anio"<<endl;
cout<<"==================================="<<endl;
cin>>fech.y;
float edad=fechanac(fech);
if(val_dev==MESES)
{
cout<<"nnTienes "<<edad<<" meses........nnn"<<endl;
}
else
{
cout<<"nnTienes "<<edad<<" años........";
if((edad>0)&&(edad<30))
{
cout<<"........nnn"<<endl;
}
else if((edad>=30)&&(edad<40))
{
cout<<" y estas en el tercer escalon picarooooon...nnn"<<endl;
}
else if((edad>=40)&&(edad<=50))
{
cout<<" y estas en el cuarto escalon picarooooon...n...Todo lo que sube tienen caer jajajajannn"<<endl;
}
else if(edad>=50)
{
cout<<" y estas en la tercera edad picarooooon...n...Perdona que te lo diga pero hueles camajonnnn"<<endl;
}
}
getchar();
cout<<"nnnnn Si deseas continuar into S/N"<<endl;
cin>>res;
system("pause");
system("cls");
}
while((res=='s')||(res=='S'));
return 0;
}