
Ayuda examen en menos de dos horas
Publicado por engel (1 intervención) el 18/03/2017 09:06:45
me podrian ayudar debo hacerle la prueba de caja negra a este codigo que envio la profesora , pero no compila en ningun lenguaje de programacion
// // main.c
// test
// // main.c
// test
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LENGTH 100
typedef struct Candidato Candidato;
struct Candidato{
char nombre[LENGTH];
unsigned int region[6];
unsigned int total; };
void escribir(char *str, FILE *f)
{ fgets(str, LENGTH , f);
char *ptr = strchr(str, '\n');
if (ptr)
{ *ptr = 0; }
else
{ int c;
while ((c = getchar() != '\n' && c != EOF)); } }
//Esta funcion de abajo es para determinar el mejor voto unsigned int AltoVotos
(unsigned int voto[], int n)
{ int max = 0;
for (int i = 0; i < n; i++)
{ if (max < voto[i]) max = voto[i];
} return max; }
int main(int argc, const char * argv[]) { int i; unsigned int n;
numeroCandidatos, candidatoIndex = 0, masAlto = 0;
do{ printf("Digite el numero de candidatos : ");
scanf("%u", &numeroCandidatos);
getchar(); }
while(numeroCandidatos <= 0);
Candidato estudiante[numeroCandidatos];
unsigned int arrayDeVotos[numeroCandidatos];
while (numeroCandidatos > 0)
{ printf("Digite el nombre del candidato # %u : ", ++candidatoIndex); escribir(estudiante[candidatoIndex-1].nombre, stdin);
printf("Digite sus votos en cada region\n");
estudiante[candidatoIndex - 1].total = 0;
for (i = 1; i <= 6; i++)
{ unsigned int voto;
printf("region %d : ", i);
scanf(" %d", &voto);
estudiante[candidatoIndex-1].region[i-1] = voto;
estudiante[candidatoIndex - 1].total += voto;
getchar(); }
arrayDeVotos[candidatoIndex-1] = estudiante[candidatoIndex - 1].total; numeroCandidatos--; } printf("\n\n--------------------El resultado-------------------------\n\n");
printf("Candidatos \n\n");
for (i = 0;
i < candidatoIndex; i++)
{ printf("--%s ", estudiante[i].nombre);
for (int j = 0; j < 6; j++)
{ printf("%u ", estudiante[i].region[j]);
}
printf("Totales : %u", estudiante[i].total);
printf("\n\n"); }
masAlto = AltoVotos(arrayDeVotos, candidatoIndex);
for (i = 0; i < numeroCandidatos; i++)
{ if (masAlto == estudiante[i].total) break; }
printf("\n\nEl ganador es : %s, totales : %u\n\n", estudiante[i].nombre, estudiante[i].total); }
Valora esta pregunta


0