Usuario
Como hacer un loto

Pregunta
-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Solucion_Loto_Internacional
{
class Program
{
static string[] usuario;
static int opcion;
static bool listo = false;
static Random r = new Random();
static int[] carton = new int[1];
static int[] numero = new int[5];
static int[,] matriz;
static string var;
static int contador=0;
static void Main(string[] args)
{
do
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(" \n Menu ");
Console.WriteLine("1.-Registro del usuario");
Console.WriteLine("2.-Generar Cartones de juego ");
Console.WriteLine("3.-Realizar Sorteo");
Console.WriteLine("4.-Salir del programa");
var = Console.ReadLine();
while (!int.TryParse(var,out opcion) || opcion<1 || opcion > 4)
{
var = Console.ReadLine();
}
Console.ForegroundColor = ConsoleColor.Gray;
switch (opcion)
{
case 1:
registroUsuario();
break;
case 2:
generarCarton();
break;
case 3:
sorteo();
break;
case 4:
salir();
break;
}
} while (!listo);
}
private static void sorteo()
{
bool repetir;
int aux;
int[] sorteo =new int[5];
if (matriz == null || usuario == null)
{
Console.WriteLine("Primero debe registrarse y generar cartola");
}
else
{
Console.Write("Los resultados del torneo son: ");
for (int i = 0; i < 5; i++)
{
do
{
aux = r.Next(1, 99);
repetir = false;
for (int j = 0; j <= i - 1; j++)
{
if (aux == sorteo[j])
{
repetir = true;
}
}
} while (repetir);
sorteo[i] = aux;
Console.Write(" " + sorteo[i] + " ");
}
Console.WriteLine();
for (int f = 0; f < carton[0]; f++)
{
contador = 0;
Console.Write("\nCarton No.1 ");
for (int c = 0; c < 5; c++)
{
if (matriz[f, c] == sorteo[c])
{
contador++;
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[" + matriz[f, c] + "]");
Console.ForegroundColor = ConsoleColor.Gray;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("[" + matriz[f, c] + "]");
Console.ForegroundColor = ConsoleColor.Gray;
}
}
Console.WriteLine("= " + contador + " puntos");
}
}
}
private static void registroUsuario()
{
do
{
Console.WriteLine("Ingrese usuario (Nombre y apellido)");
var = Console.ReadLine();
Console.WriteLine();
usuario = var.Split(' ');
} while (usuario.Length > 2 );
Console.WriteLine();
Console.WriteLine("Hola {0} {1}, bienvenido al sistema de juegos Loto Internacional", usuario[0], usuario[1]);
Console.WriteLine();
}
private static void generarCarton()
{
bool repetir;
int aux;
Console.WriteLine("Ingrese numeros de carton");
var = Console.ReadLine();
while(!int.TryParse(var,out carton[0]) || carton[0] < 2 || carton[0] > 10)
{
var = Console.ReadLine();
}
matriz = new int[carton[0], 5];
for (int f = 0; f < carton[0]; f++)
{
Console.Write("\nCarton No.1 ");
for (int c = 0; c < 5; c++)
{
for (int i = 0; i < 5; i++)
{
do
{
aux = r.Next(1, 99);
repetir = false;
for (int j = 0; j <= i - 1; j++)
{
if (aux == numero[j])
{
repetir = true;
}
}
} while (repetir);
numero[i] = aux;
}
int[] arrayOrdenado = (int[])numero.Clone();
Array.Sort(arrayOrdenado);
foreach (var auxi in arrayOrdenado)
{
matriz[f, c] = auxi;
}
Console.Write("[" + matriz[f, c] + "] ");
}
}
}
private static void salir()
{
if (!listo)
{
listo = true;
}
}
}
}