LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with array and case

 

I got a task for classes and I have a huge problem with it.


Write a program that:
- It has two arrays of type int,
- Creates a third array, each element of which is the sum of elements of input arrays with the same index,
- if the calculated result is negative, add 5

Tip: use the case

I am just starting to learn in this programming environment and it is very difficult for me.
Would anyone be able to help me?

0 Kudos
Message 1 of 8
(1,938 Views)

What have you tried so far? What did you learn in class about arrays? Have you read the material that was assigned? This is a pretty detailed, straight-forward problem. I'm not sure what "help" someone is going to be since doing your homework for you is not helping you. 

0 Kudos
Message 2 of 8
(1,932 Views)

What you are loking to do is very simple. You need to take some time and learn LabVIEW. Here are some links that will get you started:

 

http://www.ni.com/getting-started/labview-basics/

http://www.ni.com/academic/students/learn/

http://www.learnni.com/

 

Good Luck

Tim
GHSP
0 Kudos
Message 3 of 8
(1,927 Views)

Like johntrich said, this is quite well described as problems go.

Have you been able to create your two arrays and then add them?

Can you populate an array indicator with the sum of the first two, with the expected results?

 

Spoiler
As a side note (and probably not what you should be considering for this homework problem): is it possible to do this without iterating over the elements when adding the 5? I can't mentally picture if there's a way to conditionally add values based on e.g. an array of booleans... Perhaps boolean to 0,1, then multiplication, then addition? Hmm...

Edit: yes. That works.

GCentral
0 Kudos
Message 4 of 8
(1,925 Views)

I have big problem with case selector. When I join int to make it work at all, the program sums up what it takes but does not add 5 if the result is negative. 

0 Kudos
Message 5 of 8
(1,924 Views)

@wojtekmkr wrote:

I have big problem with case selector. When I join int to make it work at all, the program sums up what it takes but does not add 5 if the result is negative. 


The probably intended solution likely involves a For loop and indexing tunnels.


GCentral
0 Kudos
Message 6 of 8
(1,915 Views)

A ternary operator in an expression node would eliminate the need for a for loop, a case structure, a selector, and boolean conversion.

 

Spoiler

 "x<0 ? x+5: x"

Probably not the intent of the excersise though 😊.

0 Kudos
Message 7 of 8
(1,902 Views)

@wojtekmkr wrote:

Tip: use the case


Step 1: ignore "tips". 😄

 

 

Spoiler

altenbach_0-1584993403036.png

 

Of course you won't be learning about case structures and loops and such, so don't submit that as solution! 😄

You can still use it to verify correct operation of your solution...

Step 2: Go over your class notes to see how to use a case structure correctly. 😉

Message 8 of 8
(1,819 Views)