• Lenguaje

    Pascal

  • Descripción

    Leídos el nombre, sexo y edad de varias personas se desea saber:
    a) Cantidad de mujeres
    b) Porcentaje de hombres
    c) Número de personas con edad menor o igual a 20 años.

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
50
51
52
53
54
program CantidadYPorcentajeDePersonas;
uses crt;

var a, c, edad, n, sexo : integer;
var b : real;
var nombre : string;
var tecla_repetir : char;
begin
    a := 0;
    c := 0;
    n := 0;
    b := 0;
    repeat
        clrscr;
        write ('Ingresa el nombre: ');
        readln (nombre);
        write ('Ingresa el valor de edad: ');
        readln (edad);
        writeln ('Selecciona el valor de sexo.');
        writeln ('    1.- Mujer');
        writeln ('    2.- Hombre');
        write ('    : ');
        repeat
            readln (sexo);
            if (sexo<1) or (sexo>2) then
                write ('Valor incorrecto. Ingr'#130'salo nuevamente.: ');
        until (sexo>=1) and (sexo<=2);
        n := n+1;
        if sexo=1 then
            begin
                a := a+1;
            end;
        if edad<=20 then
            begin
                c := c+1;
            end;
        writeln ('Nombre: ', nombre);
        writeln;
        write (#168'Deseas repetir el proceso? (S/N): ');
        repeat
            tecla_repetir := readkey;
        until (tecla_repetir = 's') or (tecla_repetir = 'n') or (tecla_repetir = 'S') or (tecla_repetir = 'N');
    until (tecla_repetir <> 's') and (tecla_repetir <> 'S');
    if n = 0 then
        b := 0
    else
        b := 100.0*(n-a)/n;
    writeln ('Valor de a: ', a);
    writeln ('Valor de c: ', c);
    writeln ('Valor de n: ', n);
    writeln ('Valor de b: ', b:0:6);
    write ('Presiona una tecla para terminar . . . ');
    readkey;
end.