Ask coding questions

← Back to all posts
Nth root error
Bunnytoes

I am trying to get the nth root, but whenever the button is clicked in says NaN could someone please help.

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
MrVoo
Bunnytoes
Comments
hotnewtop
Coder100

not sure what your problem was but it works for me:

nan usually happens with things like 0/0.

Bunnytoes

@Coder100

did you click the nth root thing?

Coder100
Bunnytoes

@Coder100 Why doesn't it work for me then?

Coder100

anyways the NaN is because your default number is 0. What you have is you make the user type in 2 numbers usually through other operators I believe thereby setting the memValue. Then, you use it on the current value, number. By default it's probably something invalid. @Bunnytoes

Bunnytoes

@Coder100 how did you use it? I tried 3 the button and then it said NaN can you tell me the order?

Bunnytoes

@Coder100 double k = cl.number,n=temp; I set the values temp I think is a pressed number but that might be it but why does it work for you?

Coder100

8 + 2 nthroot @Bunnytoes

Bunnytoes

@Coder100 thank you so much!!!!! But why does that work?

Coder100

i believe its how you are doing them.

For example, addition is like this: 1 + 2
but your nthroot is like this: 1 2 nthroot

however, if you just do 2 nthroot clearly its nan because the arguments are incorrect

so treat it like addition and do 1 nthroot 2 or smth @Bunnytoes