Delete matrix data

1

I have this method:

static void muestro(int[,] matriz) //MOSTRAR APUESTAS
        {
            for (int fila = 0; fila < matriz.GetLength(0); fila++)
            {
                for (int col = 0; col < matriz.GetLength(1); col++)
                {
                    Console.Write(matriz[fila, col] + "\t");
                }
                Console.WriteLine();
            }
            Console.ReadLine();

        }

and here I invoke it in the main:

case 5:
    Console.WriteLine(listado de apuestas: ");
    mostrar(matriz);

    break;

But at the time of listing does not show me the name of the bettor, and therefore when I eliminate the bettor does not eliminate the bet, because when I return to list it keeps appearing, I need you to show me all the bets of all the bettors

    
asked by eleaefe 23.06.2017 в 15:34
source

2 answers

2

One of your mistakes is that in the function you receive an array of string instead of an array of int . Another mistake is that in that list you are looking for the first and last name, when you never pass as a parameter your list with names and surnames.

What you have to do is that when you find the person with that name and last name, you go through the bets in a position back. So you only eliminate the bet of the indicated person. And if you are going to eliminate that person's bet, it would also be necessary to delete their name and surname data, because otherwise the relationship between the positions of the arrangements would be outdated.

Try this:

static bool eliminar(int[] lista, string[] nombres, string[] apellidos, string nombre, string apellido, ref int tope) //ELIMINAR EN UN ARRAY
    {
        bool e = false;
        for (int i = 0; i < tope; i++)
        {
            if (nombres[i] == nombre && apellidos[i] == apellido)
            {
                e = true;
                for(int j = i; j < tope - 1; j++)
                {
                    lista[j] = lista[j + 1];
                    nombres[j] = nombres[j + 1];
                    apellidos[j] = apellidos[j + 1];
                }
                break;
            }
        }
        return e;
    }

EDITED

Okay, if what you need is to show you the bet of a certain person, what you would have to do is find in what index is within your arrangements nombre[] and apellido[] and use that index in your matrix of bets:

for (int i = 0; i < nombre.count(); i++)
{
    if(nombreIngresado == nombre[i] && apellidoIngresado == apellido[i])
    {
        Console.WriteLine("La apuesta de {0} {1} es de {2}", nombre[i], apellido[i], matriz(i, i));
        break;
    }
}
    
answered by 23.06.2017 / 18:01
source
0

Without even reviewing the whole code, it does not compile because the function Eliminar receives as parameters strings , and you are sending vectors.

static bool eliminar(string[] lista, string nombre, string apellido, ref int tope)
...
string[] nombre;
string[] apellido;
...
eliminar(vector, nombre, apellido,  ref tope)

you should pass:

eliminar(vector, nombre[tope], apellido[tope],  ref tope)

But I do not know if the logic of these parameters is correct.

    
answered by 23.06.2017 в 17:38