
Evitar repetidos en Matriz
Publicado por Alejandro (3 intervenciones) el 26/06/2017 16:44:41
Tengo este código:
Métodos:
Y este en el main:
como podría controlar que los números ingresados no se repitan y no se ingresen letras en lugar de numeros?, esto mismo lo puedo aplicar luego para un Random. Es programación estructurada y puedo utilizar comparadores, variables, matrices y arrays.
Métodos:
1
2
3
4
5
6
7
8
9
10
11
12
class Program { static void agregar(int[] lista, int cantidad, ref int tope) {//agrega un nuevo elemento a un array con tope lista[tope] = cantidad; tope++; }
static void cargarjugada (int[,]m, int napostante) //CARGAR LA JUGADA PARA CADA APOSTANTE
{
for(int col=0; col<m.GetLength(1);col++)
{
m[napostante,col] = Convert.ToInt32(Console.ReadLine());
}
}
Y este en el main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
case 1: Console.Clear(); Console.WriteLine("\t\t1 - Agregue una apuesta: "); if (tope < nombre.Length) {
Console.Write("Ingrese Nombre: ");
nombre[tope] = Console.ReadLine();
Console.Write("Ingrese Apellido: ");
apellido[tope] = Console.ReadLine();
Console.Write("Ingrese su Jugada : ");
cargarjugada(matriz, tope);
agregar(vector, cantidad, ref tope);
}
else
{
Console.WriteLine("No hay mas cupos");
Console.ReadLine();
}
como podría controlar que los números ingresados no se repitan y no se ingresen letras en lugar de numeros?, esto mismo lo puedo aplicar luego para un Random. Es programación estructurada y puedo utilizar comparadores, variables, matrices y arrays.
Valora esta pregunta


0