Error showing a function

Hello again, please I have a question, I programmed an array basic operations calculator, the problem I have is trying to show the answer, it just shows an empty space. Please maybe you can tell me what I'm doing wrong:

//Decalration of variables
int menu();

void leer(char t, float *va);
void leer2(char t, float *va);
void mostrar(float *va);
void sum(float *va, float *vb, float *vc);
void res(float *va, float *vb, float *vc);
void pro(float *va, float *vb, float *vc);
void coc(float *va, float *vb, float *vc);

float v1[4];
float v2[4];
float v3[4];

void setup()
{
Serial.begin(9600);
Serial.println(" --------------------------");
Serial.println(" CALCULADORA CON VECTORES");
Serial.println(" --------------------------");
}

void loop()
{
int i, active, minuta, tam;
active = 0;

do
{
minuta = menu();

switch (minuta)
{
  case 1:
    {
      leer('A', v1);
      leer2('B', v2);
      sum(v1, v2, v3);
      mostrar(v3);
      break;
    }

  case 2:
    {
      leer('A', v1);
      leer2('B', v2);
      res(v1, v2, v3);
      mostrar(v3);
      break;
    }

  case 3:
    {
      leer('A', v1);
      leer2('B', v2);
      pro(v1, v2, v3);
      mostrar(v3);
      break;
    }

  case 4:
    {
      leer('A', v1);
      leer2('B', v2);
      coc(v1, v2, v3);
      mostrar(v3);
      break;
    }

  case 5:
    {
      active = 1;
      break;
    }
}

} while (active == 0);
}

//Declaration of reading values function
void leer(char t, float *va)
{
int i, tam;

Serial.print("\nLONGITUD DEL VECTOR--> ");
do
{
tam = Serial.parseInt();
} while (Serial.available() == 0);
Serial.println(tam);

Serial.print("INSERTAR VALORES VECTOR ");
Serial.print(t);
Serial.println("--> ");

for (i = 0; i < tam; i += 1)
{
Serial.print("V");
Serial.print("[");
Serial.print(i);
Serial.print("] = ");

do
{
  va[i] = Serial.parseFloat();
} while (Serial.available() == 0);
Serial.println(va[i]);

}
}

//Second declaration of reading values function
void leer2(char t, float *va)
{
int i, tam;

Serial.print("\nLONGITUD DEL VECTOR--> ");
do
{
tam = Serial.parseInt();
} while (Serial.available() == 0);
Serial.println(tam);

Serial.print("INSERTAR VALORES VECTOR ");
Serial.print(t);
Serial.println("--> ");

for (i = 0; i < tam; i += 1)
{
Serial.print("V");
Serial.print("[");
Serial.print(i);
Serial.print("] = ");

do
{
  va[i] = Serial.parseFloat();
} while (Serial.available() == 0);
Serial.println(va[i]);

}
}

//Function to show values
void mostrar(float *va)
{
int i, tam;

Serial.print("VECTOR RESULTANTE--> ");
Serial.print(" V: ");
Serial.print("[ ");

for (i = 0; i < tam; i += 1)
{
Serial.print(va[i]);
Serial.print(" | ");
}
Serial.println(" ]");
}

//Menu
int menu()
{
int opc;
Serial.println("MENU PRINCIPAL");
Serial.println("1. SUMA");
Serial.println("2. RESTA");
Serial.println("3. PRODUCTO");
Serial.println("4. COCIENTE");
Serial.println("5. SALIR");
Serial.print("INTRODUCIR OPCION--> ");

do
{
opc = Serial.parseInt( );
} while (Serial.available() == 0);
Serial.println(opc);
return opc;
}
//Function to add
void sum(float *va, float *vb, float *vc)
{
int i, tam;
for (i = 0; i < tam; i += 1)
{
vc[i] = va[i] + vb[i];
}
}

//Function to subtract
void res(float *va, float *vb, float *vc)
{
int i, tam;
for (i = 0; i < tam; i += 1)
{
vc[i] = (va[i]) - (vb[i]);
}
}

//Function to multiply
void pro(float *va, float *vb, float *vc)
{
int i, tam;
for (i = 0; i < tam; i += 1)
{
vc[i] = (va[i]) * (vb[i]);
}
}

//Function to divide
void coc(float *va, float *vb, float *vc)
{
int i, tam;
for (i = 0; i < tam; i += 1)
{
vc[i] = (va[i]) / (vb[i]);
}
}

maybe these lines should read

while (Serial.available() != 0)
??

Sorry, it didn't work.

OK. but i'm quite sure, you do not want to parse the Serial-Input while there is no data available (Serial.available()==0)

in the function mostrar you define a variable named tam and use ist in a for-loop, but never assign any value to ist.
ist this ok?

I think you should delete all lines reading

int i, tam;

and put ONE copy of this line to the begin, where you define your variables.

have a look here
[scope - Arduino Reference]

1 Like

Thanks a lot my friend, now it works properly:+1: