This week's book giveaway is in the Design forum. We're giving away four copies of Building Microservices and have Sam Newman on-line! See this thread for details.

Can anyone explain what is going wrong with this code. It is supposed to calculate an infinite series of fractions to find the value of pi. The series begins with 4- 4/3, 4+ 4/5 and goes on alternating from + to -, incresing the denominator by 2 after each calculation. I have tried the for and the dowhile but can't seem to make it work. I am supposed to print output displaying the amount of times that I had to calculate in order to get to 3.14, 3.141, 3.1415, and 3.14159. I have not gotten very far because I am trying to first get the loop to work right. Any help!! Thanx

First of all, please put code in UBB What are you trying to do? Increment the variable count? The simplest way is

(Do you really mean ?) Second of all, in your lower (also commented out) for loop, you increment count in the loop definition, but also with a statement like the one above. Bill

Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88

posted

0

I would try to solve this in one for loop. Something like:

It's a good idea to encapsulate functionality that is common and separable (e.g. checking the precision). Hope this helps. Bill