LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

necesito ayuda creando un programa en LabView

Crear un While Loop que calcule el cuadrado de un número.
Crear un For Loop que sume los números del 1 al N.
Implementar un Case Structure para evaluar si un número es positivo o negativo

Con su explicaion de cada estrucutura

 

0 Kudos
Message 1 of 6
(201 Views)

What help do you need?

 

A while loop cannot square a number.

A for loop cannot add numbers.

A case structure cannot tell the sign of a value.

0 Kudos
Message 2 of 6
(177 Views)

Hola,

 

Aquí tienes.

 

Saludos.

using LV 2017 on Win11
0 Kudos
Message 3 of 6
(150 Views)

Hi xespizua,

 


@xespizua wrote:

Saludos.


  • What's the point of a while loop set to stop immediately (in case 2)?
  • Why do you need this inner while loop at all when there already is an outer loop???
  • Why are there no waits in your VI? No need to run as fast as possible…
  • Why is the case selector a string instead of an enum? What happens when you type "caso 1" or "Caso 1" instead of "CASO 1"?

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 6
(146 Views)

Hi GerdW,

 

  • Even if it works ""the same way"", you are right, no need to stop inmediatly. But if you wire a false constant, the "CALCULAR CUADRADO" blank button doesn't do the mechanichal action the same way.
  • I wouldn't do it that way, but he asked about a while loop to calculate the square of a number.
  • You are right. Add a Wait (ms) function to the main while loop and wire a value.
  • I don't know. I use a combo box to chose a value, not to type one.

 

Regards.

using LV 2017 on Win11
0 Kudos
Message 5 of 6
(137 Views)

@xespizua wrote:

Hi GerdW,

 

  • Even if it works ""the same way"", you are right, no need to stop inmediatly. But if you wire a false constant, the "CALCULAR CUADRADO" blank button doesn't do the mechanichal action the same way.
  • I wouldn't do it that way, but he asked about a while loop to calculate the square of a number.
  • You are right. Add a Wait (ms) function to the main while loop and wire a value.
  • I don't know. I use a combo box to chose a value, not to type one.

  • Your inner loop needs to go! If you would wire a false constant to the termination condition, the code will forever be trapped there and nothing else will work. (not even the latch action of the button!)
  • Who is "he" and why are there these silly requirements? You already have an outer while loop and that should be enough. As I said, a while loop is a structure and cannot do squaring anyway.
  • Your FOR loop logic is incorrect because the number 1 is added twice. Think how you initialize the shift register. For example currently the result is 1 for N=0 and 2 for N=1, etc. 
  • The "SUMAR" button (and case structure) is not needed and will just delay the correct output and display a stale result until pressed after changing N.
  • The indicator should not be named "1+N" because that's incorrect. Name it "sum[1..N]" or similar.
  • As already suggested, use an enum, not a combobox. I would probably use a radio-button control (one click to change instead of click...drag...release). In fact, you can place all three code alternatives in parallel and get rid of the case structure and selector. Now any change of any control will immediately update the relevant indicator. (see picture)
  • comparing floating point numbers with zero is dangerous. Make the number an integer. You also need a third case because if the input is zero it is neither positive nor negative. (or you can label the two results as "is positive/is not positive" for example 

 

altenbach_0-1760100845525.png

 

0 Kudos
Message 6 of 6
(125 Views)