10-10-2014 04:06 PM
Hello.
I am having trouble trying to figure out how to connect a string constant to a result from a true/false function. I am creating a VI that creates a random number, then has the user enter a number in the numeric control . These 2 numbers are compared and if the user's number is smaller, I want a string constant to display "too small." If the user's number is equal I want the string constant to display "correct" and if the number is bigger, the constant will display "too large."
This is a picture of what I am doing, but notice I did not insert the string constants for "too large" and "too small" yet, as I am still trying to figure out how to connect the string constant to this.
Thanks for any help.
Solved! Go to Solution.
10-10-2014 04:12 PM
Set up a boolean array from your three conditions. Convert the array to a number and put that number in a case statement that will generate your text strings.
10-10-2014 04:26 PM - edited 10-10-2014 04:27 PM
I'm sorry I barely learned this software for a week. My class isn't even teaching this, we are supposed to watch a video at home and be expected to learn this already when we show up to class.
Are you saying to ditch the t/f functions and convert them from array to number and put these in a case structure?
10-10-2014 05:08 PM
There's a lot of ways to do what you're looking to do.
Ultimately, I'm going to guess you want to allow the user to continue trying to guess. Is that correct? If so, you're going to want to have a while loop at some point.
You want to run two comparisons. It must be either too small, too large, or equal. If it's not the first two, it must be the third.
What are you hoping to do with the selects? That just selects one of the two inputs.
If you merge them all into a logical operation, you're going to get strange results.
Take a step back from the code. Right now, you're going to confuse yourself a bit with the code. You need an algorithm first. Use real words to explain what you want to do. As an example:
Create random number in the range of 1-10.
Accept user input
...
Output result to user.
Once you have that algorithm, it will be easier for everyone, yourself included, to help your code progress.
10-10-2014 08:14 PM
Yes you are correct, I will be putting this in a while loop to have the user keep guessing.
I am sorry I do not know what to do clearly. The video shown just taught us what loops do, we were not introduced to multiple true/false things.
All I want to do is have the user guess the number, while this operation is held in a while loop. I will actually make 3 while loops I guess because the example I showed is only for 1 of them. I need to do 2 more just like that, but I'm sure if I can do one i can do multiple algorithms of this kind.
10-10-2014 08:19 PM
This is my algorithm,
Create random number in the range of 1-6.
Accept user input
Output result
compare random number result to user's input
If user's input # is smaller, show string constant saying "too small."
If user's input # is bigger, show string constant saying "too big."
If user's input # is equal, show string constant saying "correct."
There will be one string constant shown to the user, where it says "too small" "too big" or "correct."
10-10-2014 08:22 PM
My apologies as I have probably barely any knowledge on this software. I am very displeased by this class and I will be sure to write a complaint e-mail to the teacher assistant. I do not like doing an assignment on something I am not introduced to.
10-10-2014 10:52 PM
There's a thousand ways to do this. Here's a simple way using local variables.
10-10-2014 11:32 PM - edited 10-10-2014 11:37 PM
@RRogers92 wrote:
There's a thousand ways to do this. Here's a simple way using local variables.
1000 ways except this one? Isn't there going to be a race condition because all of those cases are going to execute and overwrite each other? (Your assertion that "if false, nothing will happen" is not correct. "If false, an empty string will be written (or whatever is in the string constant that looks like an empty string).)"
10-10-2014 11:38 PM
You are correct Bill, I apologize for the error. I obviously didn't even look at the code twice. Please ignore my first post.