-
Lenguaje
Pascal
-
Descripción
Se necesita un sistema que lea los votos obtenidos por tres candidatos a presidente municipal en la ciudad de Zacatecas y calcule e imprima al ganador, junto con el porcentaje obtenido de votos.
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
55
56
57
58
59
60
61
62
63
64
65
66
67
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
55
56
57
58
59
60
61
62
63
64
65
66
67
program VotosObtenidosPorTresCandidatos;
uses crt;
var voto, votos, votos_para_gerardo, votos_para_marcelo, votos_para_ricardo : integer;
var porcentaje_de_gerardo, porcentaje_de_marcelo, porcentaje_de_ricardo : real;
var tecla_repetir : char;
begin
votos_para_gerardo := 0;
votos_para_marcelo := 0;
votos_para_ricardo := 0;
votos := 0;
porcentaje_de_gerardo := 0;
porcentaje_de_marcelo := 0;
porcentaje_de_ricardo := 0;
repeat
clrscr;
writeln ('Selecciona el valor de voto.');
writeln (' 1.- Gerardo');
writeln (' 2.- Marcelo');
writeln (' 3.- Ricardo');
write (' : ');
repeat
readln (voto);
if (voto<1) or (voto>3) then
write ('Valor incorrecto. Ingr'#130'salo nuevamente.: ');
until (voto>=1) and (voto<=3);
votos := votos+1;
if voto=1 then
begin
votos_para_gerardo := votos_para_gerardo+1;
end;
if voto=2 then
begin
votos_para_marcelo := votos_para_marcelo+1;
end;
if voto=3 then
begin
votos_para_ricardo := votos_para_ricardo+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');
if votos = 0 then
porcentaje_de_gerardo := 0
else
porcentaje_de_gerardo := 100.0*votos_para_gerardo/votos;
if votos = 0 then
porcentaje_de_marcelo := 0
else
porcentaje_de_marcelo := 100.0*votos_para_marcelo/votos;
if votos = 0 then
porcentaje_de_ricardo := 0
else
porcentaje_de_ricardo := 100.0*votos_para_ricardo/votos;
writeln ('Valor de votos para gerardo: ', votos_para_gerardo);
writeln ('Valor de votos para marcelo: ', votos_para_marcelo);
writeln ('Valor de votos para ricardo: ', votos_para_ricardo);
writeln ('Valor de votos: ', votos);
writeln ('Valor de porcentaje de gerardo: ', porcentaje_de_gerardo:0:6);
writeln ('Valor de porcentaje de marcelo: ', porcentaje_de_marcelo:0:6);
writeln ('Valor de porcentaje de ricardo: ', porcentaje_de_ricardo:0:6);
write ('Presiona una tecla para terminar . . . ');
readkey;
end.
uses crt;
var voto, votos, votos_para_gerardo, votos_para_marcelo, votos_para_ricardo : integer;
var porcentaje_de_gerardo, porcentaje_de_marcelo, porcentaje_de_ricardo : real;
var tecla_repetir : char;
begin
votos_para_gerardo := 0;
votos_para_marcelo := 0;
votos_para_ricardo := 0;
votos := 0;
porcentaje_de_gerardo := 0;
porcentaje_de_marcelo := 0;
porcentaje_de_ricardo := 0;
repeat
clrscr;
writeln ('Selecciona el valor de voto.');
writeln (' 1.- Gerardo');
writeln (' 2.- Marcelo');
writeln (' 3.- Ricardo');
write (' : ');
repeat
readln (voto);
if (voto<1) or (voto>3) then
write ('Valor incorrecto. Ingr'#130'salo nuevamente.: ');
until (voto>=1) and (voto<=3);
votos := votos+1;
if voto=1 then
begin
votos_para_gerardo := votos_para_gerardo+1;
end;
if voto=2 then
begin
votos_para_marcelo := votos_para_marcelo+1;
end;
if voto=3 then
begin
votos_para_ricardo := votos_para_ricardo+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');
if votos = 0 then
porcentaje_de_gerardo := 0
else
porcentaje_de_gerardo := 100.0*votos_para_gerardo/votos;
if votos = 0 then
porcentaje_de_marcelo := 0
else
porcentaje_de_marcelo := 100.0*votos_para_marcelo/votos;
if votos = 0 then
porcentaje_de_ricardo := 0
else
porcentaje_de_ricardo := 100.0*votos_para_ricardo/votos;
writeln ('Valor de votos para gerardo: ', votos_para_gerardo);
writeln ('Valor de votos para marcelo: ', votos_para_marcelo);
writeln ('Valor de votos para ricardo: ', votos_para_ricardo);
writeln ('Valor de votos: ', votos);
writeln ('Valor de porcentaje de gerardo: ', porcentaje_de_gerardo:0:6);
writeln ('Valor de porcentaje de marcelo: ', porcentaje_de_marcelo:0:6);
writeln ('Valor de porcentaje de ricardo: ', porcentaje_de_ricardo:0:6);
write ('Presiona una tecla para terminar . . . ');
readkey;
end.