# Factorial not working "cannot convert from float to int"

I’m trying to make a simple 2d application for the “Traveller Salesmanship Problem” i’m configuring the program, i was working on everything in int, but i thougth float would be more accurate, even since i’m working with distance between 2 points.

I made a little function that gives me back the factorial, that represents the amount of paths that exist, when it was int it worked just fine, but when i changed everything to float it didn’t worked anymore, and i don’t know why…

``````//Quantidade de circulo]
float ct = 4;
//Comprimento e Largura de Circulo
float c1 = 6, a1 = 6;
int i, j;
float fase = 0, cfase1 = 0, cfase2 = 0, cfase3 = 0;
float[] c = new float[fact(ct)];

PVector[] p = new PVector[ct];

void setup() {
size (200, 200);
background(255);
println(c);
}

static final float fact(float num) {
return num == 1? 1: fact(num - 1)*num;
}

void draw() {

//Desenhando os Círculos

if (fase==0) {
for (i=0; i<ct; i++) {
p[i] = new PVector(random(c1, width - c1), random(a1, height - a1));
ellipse(p[i].x, p[i].y, c1, a1);
//ct - 1 para a quantidade de circulos sempre ser "ct^2"
if (cfase1 >= ct - 1) {
fase++;
}
}
cfase1++;
} else if (fase==1) {
for (i=0; i < fact(ct); i++) {
for (j = 0; j < ct; j++) {
//Calculo entre duas distancias
c[i] = sqrt(pow(p[i+1].x - p[i].x, 2) + pow(p[i+1].y - p[i].y, 2));
if (cfase2 >= ct) {
fase++;
}
cfase2++;
}
}
}
}

``````
1 Like

I just figured it out! Just needed to think a little about what the data was for!!!

``````//Quantidade de circulo]
int ct = 4;
//Comprimento e Largura de Circulo
float c1 = 6, a1 = 6;
int i, j;
float fase = 0, cfase1 = 0, cfase2 = 0, cfase3 = 0;
float[] c = new float[fact(ct)];

PVector[] p = new PVector[ct];

void setup() {
size (200, 200);
background(255);
println(c);
}

static final int fact(int num) {
return num == 1? 1: fact(num - 1)*num;
}

void draw() {

//Desenhando os Círculos

if (fase==0) {
for (i=0; i<ct; i++) {
p[i] = new PVector(random(c1, width - c1), random(a1, height - a1));
ellipse(p[i].x, p[i].y, c1, a1);
//ct - 1 para a quantidade de circulos sempre ser "ct^2"
if (cfase1 >= ct - 1) {
fase++;
}
}
cfase1++;
} else if (fase==1) {
for (i=0; i < fact(ct); i++) {
for (j = 0; j < ct; j++) {
//Calculo entre duas distancias
c[i] = sqrt(pow(p[i+1].x - p[i].x, 2) + pow(p[i+1].y - p[i].y, 2));
if (cfase2 >= ct) {
fase++;
}
cfase2++;
}
}
}
}

``````
2 Likes