"Kraig" <(E-Mail Removed)> wrote in message

news:Hgj3d.178780$%(E-Mail Removed) ...

> That's where I got lost, on the #define part. I had, to no avail:

>

> #include <iostream>

> #include <cmath>

> using namespace std;

>

> int main()

> {

> float fCalcPI = 0;

> float fTerms = 0;

>

> cout << "Enter number of terms.\n";

> cin >> fTerms;

>

> fCalcPI = fTerms - (fTerms/3) + (fTerms/5) - (fTerms/7) + (fTerms/9) -

> (fTerms/11);

>

> cout << "Pi is " << fCalcPI << " \n";

>

> return 0;

> }

>

> Like I said, I'm learning as I go. Please be patient

>

> kraig
Well I can see a few problems here. Firstly you are not using a loop, but

the problem you have to solve is 'the best way using loops, to compute pi to

say, 14 terms using values that double each time through the loop'. Clearly

you must use a loop somewhere.

Secondly you code does nothing like calculate PI. I still don't know what

the formula is that you are trying to use (if I did I would be able to help

you better). But look at what you wrote

cout << "Enter number of terms.\n";

cin >> fTerms;

fCalcPI = fTerms - (fTerms/3) + (fTerms/5) - (fTerms/7) + (fTerms/9) -

(fTerms/11);

Suppose I entered 14 as the number of terms, then the calculation would be

fCalcPI = 14 - (14/3) + (14/5) - (14/7) + (14/9) - (14/11);

which is nothing at all like the correct value of PI.

For the number of terms you want something like this

cout << "Enter number of terms.\n";

int fTerms;

cin >> fTerms;

for (int i = 0; i < fTerms; ++i)

{

...

}

See? That is a loop, and the program will go round the loop the same number

of times as the number of terms that the user entered. You have to fill in

the ... part (and a bit more). I would imagine (but I don't know this

formula) that you need to sum some series. So each time around the loop you

add another term to a total, something like this

float fTotal = 0;

cout << "Enter number of terms.\n";

int fTerms;

cin >> fTerms;

for (int i = 0; i < fTerms; ++i)

{

fTotal += ...;

}

Again you've still got to fill in the ... part. And I'm guessing here, it

might be that the formula you have in mind is completely different.

Also note that fTerms is an integer. For some reason you have declared it as

a float. But the number of terms must be an integer, you cannot have half a

term!

john