10-13-2021 09:27 PM
plz could someone help how i can generate 10 random numbers and display their sum as well as the 5th random number generate.
Solved! Go to Solution.
10-13-2021 09:42 PM - edited 10-13-2021 09:43 PM
I would start with the training resources listed at the top of the forum. (...and what does this have to do with tunnels?).
Start simple and go from there?
10-14-2021 05:34 PM
thank you for ur reply the problem that i try to solve it:
10-14-2021 06:40 PM - edited 10-14-2021 06:41 PM
so... how far did you get?
Nobody here will do your homework, but we are willing to help answer specific questions? Do you have a specific questions?
10-14-2021 07:50 PM
i states the problem to clarify why i mention the tunnels because i need to use the for loop. i built the program but i don't know how to generate the 5th random number and how to generate the sum with "add array element" function
10-14-2021 09:43 PM
You might be "overthinking" this. Suppose you can generate 10 random numbers, and you figure out how to get them all into an array. Your "statement of the problem" says you should use the "Add Array Elements" function -- do you have an Array to give to this function? You are taking a LabVIEW class -- did you learn anything about the functions on the Array Palette? Do you know how to use the LabVIEW Help to get LabVIEW to tell you what the functions do, and how to use them? Fortunately for you, LabVIEW has made "creating an Array using a For Loop" much easier than it used to be (I think this "new feature" is now around 10 years old ...), and For Loops "do this by default".
How will you know that your code works? Simple -- run it and see! Now, granted, seeing if the sum is correct is "hard" (adding 10 numbers "by hand" -- ugh!), but seeing if the number you think is the 5th agrees with looking at the entire array and counting (1, 2, 3, 4, 5) and seeing if it really is the 5th (and not, say, the 6th) is pretty easy.
But a way to make the whole example even easier is to make a small variation in the problem and turn it into one you can do in your head. Here are two variations that you can try (more practice for you, and a "feel-good" feeling when you "get the right answer" --
So if you solve the original Homework Problem, then write two additional little LabVIEW routines to do "simpler" problems, you get 3 times the training in creating and using For Loops and Arrays, and will give you more confidence in your LabVIEW skills, and maybe suggest that sometimes you can "solve a simpler problem first" to be sure you understand what's going on.
Bob Schor
Bob Schor
10-14-2021 09:43 PM
Use an autoindexing output tunnel on your FOR loop to build up the array of random numbers. After that, you can use Index Array to get a specific element and use the Add Array Elements to get the total sum.
10-14-2021 10:34 PM
Thank you for your help . it works 😊
10-14-2021 10:38 PM
thank you so much.
10-15-2021 07:26 AM - edited 10-15-2021 07:32 AM
@crossrulz wrote:
Use an autoindexing output tunnel on your FOR loop to build up the array of random numbers. After that, you can use Index Array to get a specific element and use the Add Array Elements to get the total sum.
I agree that this is the right way to do this, but Index Array is not one of the allowed structures. The teacher has made this unnecessarily complicated and will likely lead the students into poor habits.
In order to do this using only the prescribed elements I would use a conditional tunnel and make the condition TRUE when i=4 (the fifth element in the array). Right click on the output and make it a single element then select conditional. Wire the result of the comparison to the conditional terminal.