05-02-2020 10:08 AM
exercise#2:Flipping coin
04-29-2025 12:25 PM
Hey there,
Welcome to LabVIEW! It’s totally normal to face some challenges in the beginning, but you’re on the right path by working through example problems. I’d be happy to help you out.
Exercise #1:
To solve this, you can use a For Loop that runs from 1 to n. Inside the loop, multiply the loop index by 2 to get the even numbers (2, 4, 6…2n), and add them up using a shift register. Before running the loop, make sure the input number n is a positive integer. You can use a Greater Than comparison to check that n > 0. If it's not, show a message to the user saying the input is invalid.
Exercise #2:
You can use a For Loop to repeat the coin flip 100 times. Inside the loop, use the Random Number function (0 to 1 range). If the number is > 0.5, count it as a Head; if it's ≤ 0.5, count it as a Tail. Again, use shift registers to keep track of the count for heads and tails. When the loop finishes, display both results.
If you ever want to get a feel for the concept without coding right away, you can even try to flip a coin online to understand the randomness.
Keep practicing and don’t hesitate to ask more questions—everyone starts somewhere!
04-30-2025 06:28 AM
I'm pretty sure their course has ended, 5 years later, bot.