Can not be implicitly converted from double to int. There is already an explicit conversion

0
 error en la linea 
  

edges [(i)] = Math.Sqrt (aux11 + aux12 + aux13);        public static void distance (int x, int n)              {

        for ( int i = 0; i <= n - 1; i++)
        {

            noditos[i] = i;
            if (i == x)
            {
                aristas[i] = 0;
            }
            else
            {

                double aux2 = arreglo[x].gety() - arreglo[i].gety();
                double aux3 = arreglo[x].getz() - arreglo[i].getz();
                double aux1 = arreglo[x].getx() - arreglo[i].getx();
                double aux11 = Math.Pow(aux1, 2);
                double aux12 = Math.Pow(aux1, 2);
                double aux13 = Math.Pow(aux1, 2);
                aristas[(i)] = Math.Sqrt(aux11 + aux12 + aux13);
            }
        }
    }

This is part of the code:

class Nodo
{
public int x;
public int y;
public int z;

public Nodo(int _x, int _y, int _z)
{
    this.x = _x;
    this.y = _y;
    this.z = _z;
}
public int getx()
{
    return x;
}
public int gety()
{
    return y;
}
public int getz()
{
    return z;
}


public static int[] aristas = new int[10];
public static int[] noditos = new int[10];
public static int[,] relaciones = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
public static int[] colorcito = new int[10];

public static List<Nodo> arreglo = new List<Nodo>();

public static void distancia(int x, int n)
{

    for ( int i = 0; i <= n - 1; i++)
    {

        noditos[i] = i;
        if (i == x)
        {
            aristas[i] = 0;
        }
        else
        {

            double aux2 = arreglo[x].gety() - arreglo[i].gety();
            double aux3 = arreglo[x].getz() - arreglo[i].getz();
            double aux1 = arreglo[x].getx() - arreglo[i].getx();
            double aux11 = Math.Pow(aux1, 2);
            double aux12 = Math.Pow(aux1, 2);
            double aux13 = Math.Pow(aux1, 2);
        //    aristas[(i)] = Math.Sqrt(aux11 + aux12 + aux13);
        }
    }
}
asked by skar_543 27.09.2018 в 14:57
source

1 answer

1

Change :

public static int[] aristas = new int[10];

For :

public static double[] aristas = new double[10];

Or Modify :

aristas[(i)] = Math.Sqrt(aux11 + aux12 + aux13);

By:

aristas[(i)] = Convert.ToInt32(Math.Sqrt(aux11 + aux12 + aux13));

You should know that you will return the result rounded to 0 places after the comma. If you want to round it Floor or Ceiling you just have to modify it a bit:

In case of Floor :

aristas[(i)] = Convert.ToInt32(Math.Floor(Math.Sqrt(aux11 + aux12 + aux13)));

In case of Ceiling :

aristas[(i)] = Convert.ToInt32(Math.Ceiling(Math.Sqrt(aux11 + aux12 + aux13)));
    
answered by 27.09.2018 в 18:21