• Lenguaje

    Pascal

  • Descripción

    Un maestro desea saber qué porcentaje de hombres y qué porcentaje de mujeres hay en un grupo de estudiantes.

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 PorcentajeDeMujeresYHombres;
uses crt;

var estudiantes, genero, hombres, mujeres : integer;
var porcentaje_hombres, porcentaje_mujeres : real;
var tecla_repetir : char;
begin
    estudiantes := 0;
    hombres := 0;
    mujeres := 0;
    porcentaje_hombres := 0;
    porcentaje_mujeres := 0;
    repeat
        clrscr;
        writeln ('Selecciona el valor de genero.');
        writeln ('    1.- Mujer');
        writeln ('    2.- Hombre');
        write ('    : ');
        repeat
            readln (genero);
            if (genero<1) or (genero>2) then
                write ('Valor incorrecto. Ingr'#130'salo nuevamente.: ');
        until (genero>=1) and (genero<=2);
        if genero=1 then
            begin
                mujeres := mujeres+1;
            end
        else
            begin
                hombres := hombres+1;
            end;
        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');
    estudiantes := hombres+mujeres;
    if estudiantes = 0 then
        porcentaje_hombres := 0
    else
        porcentaje_hombres := 100.0*hombres/estudiantes;
    if estudiantes = 0 then
        porcentaje_mujeres := 0
    else
        porcentaje_mujeres := 100.0*mujeres/estudiantes;
    writeln ('Valor de estudiantes: ', estudiantes);
    writeln ('Valor de hombres: ', hombres);
    writeln ('Valor de mujeres: ', mujeres);
    writeln ('Valor de porcentaje hombres: ', porcentaje_hombres:0:6);
    writeln ('Valor de porcentaje mujeres: ', porcentaje_mujeres:0:6);
    write ('Presiona una tecla para terminar . . . ');
    readkey;
end.