Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- //se declaran los structs
- struct region {
- char nombre[50];
- int numero;
- unsigned int votos[6];
- };
- struct candidato {
- char nombre[50];
- unsigned int votos;
- };
- struct elecciones {
- struct region regiones[15];
- struct candidato candidatos[6];
- int poblacionChilena;
- };
- struct auxiliares {
- int numero;
- int votos;
- };
- //se inicia el programa
- int main()
- {
- struct elecciones datos;
- int i,TotalDeVotos=0,j;
- char *regionesChile[15] = {"Tarapaca", "Antofagasta", "Atacama", "Coquimbo", "Valparaiso", "O'Higgins", "Maule", "Bio-Bio", "La Araucania", "Los Lagos", "Aysen", "Magallanes", "Santiago", "Los Rios", "Arica y Parinacota"};
- char *candidatosChile[6] = {"Sebastian Pinera", "Beatriz Sanchez", "Alejandro Guillier", "MEO", "Carolina Goic", "Alejandro Navarro"};
- //copio los datos de los arreglos a los structs
- for (i=0; i<15; ++i)
- {
- strcpy(datos.regiones[i].nombre,regionesChile[i]);
- datos.regiones[i].numero=i;
- }
- for (i = 0; i<6; ++i)
- {
- strcpy(datos.candidatos[i].nombre,candidatosChile[i]);
- }
- //obtengo la poblacion chilena
- scanf("%d",&datos.poblacionChilena);
- //se realizan las votaciones
- for (j = 0; j < 15; ++j)
- {
- for ( i = 0; i < 6; ++i)
- {
- scanf("%d",&datos.regiones[j].votos[i]);
- TotalDeVotos+=datos.regiones[j].votos[i];
- }
- }
- int aSumar;
- //calculo el numero de votos que tiene cada candidato
- for (j = 0; j < 6; ++j)
- {
- for ( i = 0; i < 15; ++i)
- {
- aSumar+=datos.regiones[i].votos[j];
- datos.candidatos[j].votos+=aSumar;
- printf("%s \n",datos.candidatos[j].nombre);
- aSumar=0;
- if(datos.candidatos[j].votos>TotalDeVotos)
- {
- printf("ERR0R\n");
- }
- }
- printf("%d\n",datos.candidatos[j].votos);
- }
- //Saco el culiao con mas votos
- struct auxiliares aux1,aux2;
- for (i = 0; i < 6; ++i)
- {
- if (datos.candidatos[i].votos>=aux1.votos)
- {
- aux2.votos=aux1.votos;
- aux2.numero=aux1.numero;
- aux1.votos=datos.candidatos[i].votos;
- aux1.numero=i;
- }
- }
- //Printeo los resultados
- if(aux1.votos>(TotalDeVotos/2)+1)
- {
- printf("Con un total de %d votos, se declara Presidente a: %s con %d votos.",TotalDeVotos,datos.candidatos[aux1.numero].nombre,datos.candidatos[aux1.numero].votos);
- }
- else
- {
- printf("Con un total de %d votos, se declara segunda vuelta entre: %s y %s con %d y %d votos respectivamente.",TotalDeVotos,datos.candidatos[aux1.numero].nombre,datos.candidatos[aux2.numero].nombre,datos.candidatos[aux1.numero].votos,datos.candidatos[aux2.numero].votos);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement