Hi, is there any way to change a string to a number? I can't find it on the website so I am asking the forum. Thanks.
To convert a string containing a number (or really any mathematical expression), use the expr( command. This will evaluate the number, variable, or expression in the string of choice and save the value to Ans (or a variable if you store it).
The solution to a complex problem is often a simple answer.
I've tried it, but what I need to do is to do this:
I need to be given an input, given an answer, and be able to tell if it is correct or not. The answer is stored as I and I don't want the person to put in just the variable I to cheat the system. I also don't want any errors occuring in the problem. I don't tghinjk the expr( command is going to cut it.
I did this before for a program. The best way is to convert the target answer to a string and then compare the string input to the target string. You can use Number to String algorithm do do the conversions.
The point is say the answer is sqrt(2. The calculator uses it as 1.414… So when you convert it to a string, if you have sqrt(2 , it won't be accepted.
Could you provide more context about the program so that we can better understand what you need?
I think what he is looking for is the kind of input checking that the powers of 2 game that you made used. He probably didn't fully understand your last post.
Get user input as a string. Let's say the users inputs "A+B"
Calculate the correct answer, A+B=5, use number to string algorithm to turn it into a string, "5".
Check if the strings are identical. "A+B" is not the same as "5"
However, if the inputted string has a syntax problem (ex. str1="5+-") When you calculate it by doing the expr( command it will give a syntax error. I dont want that. However, yes that os what im trying to do without the errors.
So what it does is the program solves a solution and the person is given an input, too see if the input is the same as the answer. I dont want them to just answer a varoable to get it right
You have to convert the answer calculated by the program to a string, and then compare that to the string that the user input. You do not need to use expr(. I could post an example if you still don't understand.
I understand this, but say the answer is sqrt(2). The calculator stores this as 1.414..blah blah blah… however, if the user inputs sqrt(2) it will be counted as wrong.
In that case, you can use a square-root simplifier to generate a string. If you know what the answers should be ahead of time, you can store them in a string with delimiters and use inString( and sub( to extract the answer.