Generation

fix invalid codeWed, 04 Sep 2024

// Variables para los votos de cada candidato int votosDS = 0; int votosAA = 0; int votosNM = 0; int votosR = 0; void Main() { while (true) { Console.Clear(); string div = new string('-', 20); /* Bienvenida */ Console.WriteLine($"{div}Bienvenido al portal de votaciones 2030{div}\n"); Console.WriteLine("Candidatos: " + "1. Dr. Simi" + "2. Alfredo Adame" + "3. Niurka Marcos" + "4. Rafiki"); Console.WriteLine($"{div}\n"); Console.WriteLine("5. Mostrar Graficas" + "6.Simular elecciones"); Console.WriteLine($"{div}\n"); Console.WriteLine("Seleccione una opcion: "); string opcion = Console.ReadLine(); // Las opciones switch (opcion) { case "1": votosDS++; break; case "2": votosAA++; break; case "3": votosNM++; break; case "4": votosR++; break; case "5": MostrarGraficas(); break; case "6": SimularElecciones(); break; default: Console.WriteLine("Opcion no valida. Presione cualquier tecla para seguir"); Console.ReadKey(); break; } Console.Clear(); } } void MostrarGraficas() { // Calcular el total de votos int totalVotos = votosDS + votosAA + votosNM + votosR; if (totalVotos == 0) { Console.WriteLine("No hay votos registrados"); return; } // Calcular porcentajes double porcentajesSimi = (double)(votosDS) / totalVotos * 100; double porcentajesAdame = (double)votosAA / totalVotos * 100; double porcentajesNiurka = (double)votosNM / totalVotos * 100; double porcentajesRafiki = (double)votosR / totalVotos * 100; // Resultados con barras Console.WriteLine($"Dr. Simi tiene un total de {porcentajesSimi}% {new string('-', (int)porcentajesSimi)}"); Console.WriteLine($"Alfredo Adame tiene un total de {porcentajesAdame}% {new string('-', (int)porcentajesAdame)}"); Console.WriteLine($"Niruka Marcos tiene un total de {porcentajesNiurka}% {new string('-', (int)porcentajesNiurka)}"); Console.WriteLine($"Rafiki tiene un total de {porcentajesRafiki}% {new string('-', (int)porcentajesRafiki)}"); //Mostrar al ganador MostrarGanador(); //Pausa para que vean los resultados Console.WriteLine("Presione cualquier tecla para continuar"); Console.ReadKey(); } // Simular elecciones void SimularElecciones() { //Generar numero aleaorio Random random = new Random(); int votantes = random.Next(110, 131); // Simular los votos de cada cotante for (int i = 0; i < votantes; i++) { int votoAleatorio = random.Next(1, 5); switch (votoAleatorio) { case "1": votosDS++; break; case "2": votosAA++; break; case "3": votosNM++; break; case "4": votosR++; break; } } Console.WriteLine($"Simmulacion completa: {votantes} personas participaron"); Console.WriteLine("Presione cualquier tecla para continuar"); Console.ReadKey(); } // Determinar el ganador o un empate void MostrarGanador() { int votostotal = (votosDS + votosAA + votosNM + votosR); // Mostrar al ganador string ganadores = ""; int numganadores = 0; for (int i = 1; i < 5; i++) { switch (i) { case "1": if (votosDS == votostotal) { ganadores += "Dr. Simi"; numganadores++; } break; case "2": if (votosAA == votostotal) { ganadores += "Alfredo Adame"; numganadores++; } break; case "3": if (votosNM == votostotal) { ganadores += "Niurka Marcos"; numganadores++; } break; case "4": if (votosR == votostotal) { ganadores += "Rafiki"; numganadores++; } break; } } // Mostrar ganador o empate if (numganadores > 1) { Console.WriteLine($"Empate entre: {ganadores} con {votostotal}"); } else { Console.WriteLine($"El ganaodor es: {ganadores} con {votostotal}"); } }

fix invalid code: def add(a, b): return a - b ``` def add(a, b): return a + b ``` fix invalid code: // Variables para los votos de cada candidato int votosDS = 0; int votosAA = 0; int votosNM = 0; int votosR = 0; void Main() { while (true) { Console.Clear(); string div = new string('-', 20); /* Bienvenida */ Console.WriteLine($"{div}Bienvenido al portal de votaciones 2030{div}\n"); Console.WriteLine("Candidatos: " + "1. Dr. Simi" + "2. Alfredo Adame" + "3. Niurka Marcos" + "4. Rafiki"); Console.WriteLine($"{div}\n"); Console.WriteLine("5. Mostrar Graficas" + "6.Simular elecciones"); Console.WriteLine($"{div}\n"); Console.WriteLine("Seleccione una opcion: "); string opcion = Console.ReadLine(); // Las opciones switch (opcion) { case "1": votosDS++; break; case "2": votosAA++; break; case "3": votosNM++; break; case "4": votosR++; break; case "5": MostrarGraficas(); break; case "6": SimularElecciones(); break; default: Console.WriteLine("Opcion no valida. Presione cualquier tecla para seguir"); Console.ReadKey(); break; } Console.Clear(); } } void MostrarGraficas() { // Calcular el total de votos int totalVotos = votosDS + votosAA + votosNM + votosR; if (totalVotos == 0) { Console.WriteLine("No hay votos registrados"); return; } // Calcular porcentajes double porcentajesSimi = (double)(votosDS) / totalVotos * 100; double porcentajesAdame = (double)votosAA / totalVotos * 100; double porcentajesNiurka = (double)votosNM / totalVotos * 100; double porcentajesRafiki = (double)votosR / totalVotos * 100; // Resultados con barras Console.WriteLine($"Dr. Simi tiene un total de {porcentajesSimi}% {new string('-', (int)porcentajesSimi)}"); Console.WriteLine($"Alfredo Adame tiene un total de {porcentajesAdame}% {new string('-', (int)porcentajesAdame)}"); Console.WriteLine($"Niruka Marcos tiene un total de {porcentajesNiurka}% {new string('-', (int)porcentajesNiurka)}"); Console.WriteLine($"Rafiki tiene un total de {porcentajesRafiki}% {new string('-', (int)porcentajesRafiki)}"); //Mostrar al ganador MostrarGanador(); //Pausa para que vean los resultados Console.WriteLine("Presione cualquier tecla para continuar"); Console.ReadKey(); } // Simular elecciones void SimularElecciones() { //Generar numero aleaorio Random random = new Random(); int votantes = random.Next(110, 131); // Simular los votos de cada cotante for (int i = 0; i < votantes; i++) { int votoAleatorio = random.Next(1, 5); switch (votoAleatorio) { case "1": votosDS++; break; case "2": votosAA++; break; case "3": votosNM++; break; case "4": votosR++; break; } } Console.WriteLine($"Simmulacion completa: {votantes} personas participaron"); Console.WriteLine("Presione cualquier tecla para continuar"); Console.ReadKey(); } // Determinar el ganador o un empate void MostrarGanador() { int votostotal = (votosDS + votosAA + votosNM + votosR); // Mostrar al ganador string ganadores = ""; int numganadores = 0; for (int i = 1; i < 5; i++) { switch (i) { case "1": if (votosDS == votostotal) { ganadores += "Dr. Simi"; numganadores++; } break; case "2": if (votosAA == votostotal) { ganadores += "Alfredo Adame"; numganadores++; } break; case "3": if (votosNM == votostotal) { ganadores += "Niurka Marcos"; numganadores++; } break; case "4": if (votosR == votostotal) { ganadores += "Rafiki"; numganadores++; } break; } } // Mostrar ganador o empate if (numganadores > 1) { Console.WriteLine($"Empate entre: {ganadores} con {votostotal}"); } else { Console.WriteLine($"El ganaodor es: {ganadores} con {votostotal}"); } } ```

Questions about programming?Chat with your personal AI assistant