LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to make this very simple arithmetic question generator work

Hi, as part of a school project, I've been developing this simple arithmetic question generator (for small kids, like really small). It uses random to generate two values between 1-9 and another random is connected to a ring which has the operations Addition/Subtraction/Multiplication (to display), and the value is also connected to a case structure that lets the VI know which operation to check for with number 1 and 2. Each time user enters a value in the answer field and presses the button Check Answer, the current answer should be checked with the result of the actual operation of [random number 1] [random operation] [random number 2], and if it is correct, Point value gets incremented by 1, and numbers randomized again. If incorrect, point value stays same but numbers are randomized anyway.

 

In my case, all the values generate fine, the only issue is point doesn't get incremented for some reason. I've tried rearranging everything a few times, and now I've noticed I get a point if the answer currently typed in the field, by an odd stroke of luck, accidentally matches up with the correct value for the new numbers and operations generated when clicking Check Answer (The NEXT question). This is currently more a program to test for precognition than arithmetic ability Smiley Very Happy If anybody could look over as to why, it'd be great, thanks!

Download All
0 Kudos
Message 1 of 6
(2,516 Views)

Please include a Snippet of your code, I don't have your version of LabVIEW.

 

It sounds like you might have an issue with your dataflow. The Highlight Execution feature is a great way to watch how your application utilizes dataflow.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 6
(2,507 Views)

Alright, adding it to the initial post now 🙂

0 Kudos
Message 3 of 6
(2,503 Views)

Hmm, interesting application!

To quickly fix your problem, you can remove the Feedback Node (this is what's causing the precognition test) and use a local variable for Op as the input to the case structure.

 

A more reliable way to do this would be to take a look at the Event Structure. You could use this to check for button presses using the Value Change event, which would mitigate the polling necessary on the Boolean controls, and would make it easier to write some initialization code for the first test (with the fix proposed above, the first test is 0x0 = ?). I'd also suggest perhaps a subVI to do the random generation, if you want to place it both before the first test and in each regeneration.


GCentral
0 Kudos
Message 4 of 6
(2,468 Views)

Use a while loop to repeat the process rather than using the Run Continuously button. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 6
(2,449 Views)

A few more comments:

  • Please don't maximize the diagram and front panel to the screen. It is much easier to program when you can see both AND the help window at the same time. Maximized, you can only see one thing! You need the help window! Trust me on that!
  • You need a toplevel loop with a small  wait (or event structure). ("Run continuously" is only a debugging tool). Do a simple state machine, switching states as a function of user interaction.
  • Keep all your values in shift registers or feedback nodes, you could even have a single array where each value is an element.
  • To get an even probability distribution, round towards -inf, not to nearest. Currently your edge values have only half the probability of the others.
  • Once rounded, all your values are integers. All terminals and most wires should be blue (I32). ("equal" comparisons can be very dangerous on orange wires under some other scenarios. Never do that!)
  • You can combine a lot of your duplicate code into one. For example you could do the multiplication and rounding of a random number in a FOR loop, autoindexing on an array of three multipliers.
  • If you would place the terminals after the case structure, You can wire to them from both cases. No need for locals.
  • Your feedback node got inserted automatically because you wired a cycle. That "cosmetically" fixes the broken wire but logically breaks your code. (See also this idea discussion)

Try to apply most of these fixes and post your new solution again. We'll help you get it perfect. 😄

0 Kudos
Message 6 of 6
(2,425 Views)