• Lenguaje

    Pascal

  • Descripción

    Calcule el número de votos que tuvieron 4 candidatos a la alcaldía.

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
program VotosPara4Candidatos;
uses crt;

var candidato_1, candidato_2, candidato_3, candidato_4, voto : integer;
var tecla_repetir : char;
begin
    candidato_1 := 0;
    candidato_2 := 0;
    candidato_3 := 0;
    candidato_4 := 0;
    repeat
        clrscr;
        writeln ('Selecciona el valor de voto.');
        writeln ('    1.- Candidato 1');
        writeln ('    2.- Candidato 2');
        writeln ('    3.- Candidato 3');
        writeln ('    4.- Candidato 4');
        writeln ('    5.- Nulo');
        write ('    : ');
        repeat
            readln (voto);
            if (voto<1) or (voto>5) then
                write ('Valor incorrecto. Ingr'#130'salo nuevamente.: ');
        until (voto>=1) and (voto<=5);
        if voto=1 then
            begin
                candidato_1 := candidato_1+1;
            end;
        if voto=2 then
            begin
                candidato_2 := candidato_2+1;
            end;
        if voto=3 then
            begin
                candidato_3 := candidato_3+1;
            end;
        if voto=4 then
            begin
                candidato_4 := candidato_4+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');
    writeln ('Valor de candidato 1: ', candidato_1);
    writeln ('Valor de candidato 2: ', candidato_2);
    writeln ('Valor de candidato 3: ', candidato_3);
    writeln ('Valor de candidato 4: ', candidato_4);
    write ('Presiona una tecla para terminar . . . ');
    readkey;
end.