• Lenguaje

    Pascal

  • Descripción

    Pide el año, mes y día de nacimiento y calcula la edad con meses y días cumplidos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
program edad;
uses crt, dos;

const dias_del_mes : array[0..12] of integer = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var anno, mes, dia, annos, meses, dias : integer;
var tm_mday, tm_year, tm_mon, dayofweek: word;
var tecla : char;
begin
    getdate (tm_year, tm_mon, tm_mday, dayofweek);
    writeln ('Fecha actual: ', tm_year, '/', tm_mon, '/', tm_mday, #10#13);
    repeat
        write ('Ingrese el a'#164'o de nacimiento: ');
        readln (anno);
        if (anno < 1900) or (anno > tm_year) then
            writeln ('A'#164'o incorrecto.');
    until (anno >= 1900) and (anno <= tm_year);
    repeat
        write ('Ingrese el mes de nacimiento: ');
        readln (mes);
        if (mes < 1) or (mes > 12) then
            writeln ('Mes incorrecto.');
    until (mes >= 1) and (mes <= 12);
    repeat
        write ('Ingrese el d'#161'a de nacimiento: ');
        readln (dia);
        if (dia < 1) or (dia > dias_del_mes[mes]) then
            writeln ('D'#161'a incorrecto.');
    until (dia >= 1) and (dia <= dias_del_mes[mes]);
    annos := tm_year - anno;
    meses := tm_mon  - mes;
    dias  := tm_mday - dia;
    if dias < 0 then
        begin
            dias := dias + dias_del_mes[tm_mon];
            dec (meses);
        end;
    if meses<0 then
        begin
            meses := meses + 12;
            dec (annos);
        end;
    writeln;
    writeln ('A'#164'os : ', annos);
    writeln ('Meses: '     , meses);
    writeln ('D'#161'as : ', dias );
    write (#10#13'Presiones una tecla para terminar . . . ');
    tecla := readkey;
end.