Created
August 29, 2018 21:11
-
-
Save perseoq/d82bb1a1192ca1f4eb566ed2880183d7 to your computer and use it in GitHub Desktop.
Archivo en C++ que dice la edad en que naciste con uso de string.h y time.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <string> | |
using namespace std; | |
main(){ | |
time_t t=time(NULL); | |
tm* y = localtime(&t); | |
int meses=y->tm_mon; | |
string mes; | |
int x, edad; | |
int actual; | |
cout<<"Año en que naciste: "; | |
cin>>x; | |
if(meses==0){ | |
mes = "Enero"; | |
} | |
if(meses==1){ | |
mes = "Febrero"; | |
} | |
if(meses==2){ | |
mes="Marzo"; | |
} | |
if(meses==3){ | |
mes="Abril"; | |
} | |
if(meses==4){ | |
mes="Mayo"; | |
} | |
if(meses==5){ | |
mes="Junio"; | |
} | |
if(meses==6){ | |
mes="Julio"; | |
} | |
if(meses==7){ | |
mes="Agosto"; | |
} | |
if(meses==8){ | |
mes="Septiembre"; | |
} | |
if(meses==9){ | |
mes="Octubre"; | |
} | |
if(meses==10){ | |
mes="Noviembre"; | |
} | |
if(meses==11){ | |
mes="Diciembre"; | |
} | |
actual=y->tm_year+1900; | |
edad = actual - x; | |
cout<<"Tienes "<<edad<<" años "; | |
cout<<"siendo hoy el "<<y->tm_mday<<" de "<<mes<<" del "<<actual<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment