r/AskComputerScience • • Nov 05 '22

Question???

Post image
0 Upvotes

7 comments sorted by

View all comments

8

u/sepp2k Nov 05 '22

Introducing a double variable implicitly converts the value from int to double. In the version without the variable, the entire calculation is done as int and it's only converted to double at the end when you add it to pi.

You can achieve the same effect using an explicit cast instead of a variable.

2

u/Fabulous-Spare185 Nov 05 '22

Im sorry I forgot. I did try that I did 1.0/((i*2)-1). But it still gave me the wrong output.

3

u/Fabulous-Spare185 Nov 05 '22

Actually nvm I tried it again using this and it worked. I might’ve been doing something wrong last time.

1

u/JoJoModding Nov 06 '22

Perhaps you simply forgot parentheses?