LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

guess number

Solved!
Go to solution

I have developed a vi where user will guess the number and if the guess is correct it will report as win and if wrong the user will try again using state machine architecture. But the problem is for any number I guess, it report success. I am trying hard to understand why that is happening. Also I want user to give only 5 chances how can I do that. Can anyone please help me. 

 

Thank you in advance for your help

0 Kudos
Message 1 of 12
(4,569 Views)
Solution
Accepted by topic author anny321dum

Try using "highlight execution" to see what's happening to the random and guess numbers in the "enter guess" and "give a hint" cases.

Message 2 of 12
(4,541 Views)

Another hint. Look what the tunnel output is if unwired.

 

Capture.JPG

Message 3 of 12
(4,534 Views)

In "check guess", you are resetting both oranges wires to zero, meaning they will be equal (and equal zero) from then on.

 

(You also need to do something about your greedy loops. A simple program like that does not need to use 100% of a CPU core, spinning the loops as fast as the computer allows.)

 

 

Message 4 of 12
(4,532 Views)

Thank you very much for your reply. I still can't figure out what to put there at orange wires.

0 Kudos
Message 5 of 12
(4,505 Views)

@anny321dum wrote:

Thank you very much for your reply. I still can't figure out what to put there at orange wires

Whatever the current value was coming from the right side. Just wire across!

 

(did you understand my note about timing?)

0 Kudos
Message 6 of 12
(4,503 Views)

Thank you again. No I did not. Sorry!

0 Kudos
Message 7 of 12
(4,497 Views)

A while loop will execute over and over as fast as your computer's processor is able, consuming much computing power and slowing everything else down. In cases like this where the loop is just waiting for input, it's a good idea to add a brief pause in the loop (say, 100 ms) to relieve the CPU of that needless work.

Message 8 of 12
(4,479 Views)

Yes, your inner and outer loops are spinning as fast as the computer allows Millions of times per second. If you would place a 50ms wait in the loop, it would spin millions of times less without a perceptible difference seen by the user. Your PC will run cooler, you battery will last longer, and all your other running process don't have to fight for breadcrumbs of CPU time.

 

Also have a look at your architecture. You don't need the loop inside "enter uess" (sic) at all, you can use the state enum to either go back to the "enter uess" or forward to "Check guess", depending on the boolean state. No inner loop needed at all.

 

Also note that the text "enter number between ..." needs to appear when the program starts. Right now it won't unless the confirm button is pressed, at which time it gets overwritten a nanosecond later.

 

You also need to ensure that other messages don't get overwritten by new messages before the user has a chance to read them.

 

Your sequencing seems wrong too. for example the in the "give a hint" case, you need to go back to "enter uess", not to "check guess". Right?

 

Your numbers needs to be an integer once rounded, else it is very unlikely to ever guess right, because there are a near infinite number of DBLs between 1 and 10.

0 Kudos
Message 9 of 12
(4,446 Views)
Solution
Accepted by topic author anny321dum

Here's a quick draft to give you some ideas. If you want to limit the number of guesses, this can be done by keeping count in another shift register and switch states accordingly.

 

(There are probably bugs, so check for correct operation)

 

 

Message 10 of 12
(4,430 Views)