Delete fix

0
static bool elimino(int[] lista, string[] nombre, string nom, ref int tope)
{
    nom = Console.ReadLine()
    bool e = false;
    for (int i = 0; i < tope; i++)
    {
        if (nom == nombre[i])
        {
            for (int j = i; j < tope - 1; j++)
            {
                lista[j] = lista[j + 1];
                nombre[j] = nombre[j + 1];
                tope--;
                e = true;
                i = tope;
            }
        }
    }
    return e;
}

That's what I call it:

elimino(vector, nombre, nom,  ref  tope);

and I have this matrix defined in the main:

cantidad = Convert.ToInt32(Console.ReadLine());
int[] vector = new int[cantidad];
nombre = new string[cantidad];
int[,] matriz = new int[cantidad, 5];

Where quantity is the number of users (names) and 5 each lottery ball

The issue is that user login, delete, but eliminates the user, not your bet, for example if I have 2 users, one a and another b, if I eliminate a, I have the b with the 2 bets, I need to delete the user with bet of a

    
asked by eleaefe 30.06.2017 в 02:22
source

1 answer

0

As I understood you want the entire row of bets of the user that was removed from the list of names removed in the matrix.

To do this you have to do something similar with lista and nombre , but in this case you will go back whole rows, not a single element. With for you go through all the columns of the matrix and you assign those values to the same columns but from the previous row.

Another thing: the decrease of cap should not be within the for , because you would be decreasing it many times and only one should be eliminated, like the e = true; , it is not necessary to put it there, with that change once when you find the user is enough. Also, if i = tope; you put only for the first for to stop at that moment, you should put a break; instead.

I'll leave the corrected code:

static bool elimino(int[,] matriz, int[] lista, string[] nombre, string nom, ref int tope)
{
    nom = Console.ReadLine()
    bool e = false;

    for (int i = 0; i < tope; i++)
    {
        if (nom == nombre[i])
        {
            for (int j = i; j < tope - 1; j++)
            {
                lista[j] = lista[j + 1];
                nombre[j] = nombre[j + 1];
            }

            for(int j = 0; j < tope; j++)
            {
               matriz[i, j] = matriz[i + 1, j];
            }

            tope--;
            e = true;
            break;
        }
     }
    return e;
}
    
answered by 30.06.2017 в 03:43