So I'm making a program where you are given an angle and you have to input the exact value of the sine, cosine, or tangent of the angle. Let's say the answer was 1/√(3), how would I be able to enter that as my answer, and compare it to the answer that the code calculated (1/Math.sqrt(3))?
Asked
Active
Viewed 489 times
0
-
and what have you done about it? – lrleon Nov 21 '15 at 00:53
-
"input the exact *value*" is impossible, because the answer cannot be expressed *exactly* as a numeric value. You could however ask user to enter the value with N decimals of precision, and then verify that value is accurate to that precision. – Andreas Nov 21 '15 at 00:59
-
By "exact value," I mean input the value in fraction form like it is in the question rather than a rounded decimal. – Jack Burrus Nov 21 '15 at 01:01
-
how do you suppose they could do that from the command line or terminal input? – blurfus Nov 21 '15 at 01:12
-
They could enter something like 1/Math.sqrt(3) and it would work with my answer. – Timo Denk Nov 21 '15 at 08:12
1 Answers
0
One option would be calculating the value of the user input String like so: Evaluating a math expression given in string form
Then you could go ahead and simply compare the result with your "the answer that the code calculated".