# pi calculations

• 09-29-2002
nbice
pi calculations
Code:

```#include <iostream> using namespace std; int main () {         int pi1,pi2,count, x=-1, var;         while (count<1000000000){                 cout.precision(7);                 pi1=1+x(1/var);                 var=var+2;                 x=x*-1;}         if (pi1==pi2){                 count ++;}         return 0; }```
this is what i have and i can't figure out how to utilize the cout.precision(n). if you have any information on a code please i would appreciate your help a lot. i have to get calculations using double and float. using these calculations of pi. any help is very much appreciated

Leibniz ð / 4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - 1/15 + 1/17 - ...
Euler ð^2 / 6 = 1 + 1/2^2 + 1/3^2 + 1/4^2 + ...

the assignment is at http://cs.ua.edu/114/assignments/program2.htm

• 09-29-2002
Mister C
Could you tell us what you are do with this program? You can use manipulator to format your code.

Mr. C.
• 09-29-2002
kermi3
Code Tags
I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you ;)

For example:

Without code tags:

for(int i=0;i<5;i++)
{
cout << "No code tags are bad";
}

With Code Tags:
Code:

```for(int i=0;i<5;i++) {     cout << "This code is easy to read"; }```
This is of course a basic example...more complicated code is even easier to read with code tags than without.

I've added code tags for you this time. They can be added by putting [ code ] at the beginning of your code and [ /code ] at the end, only without the spaces. More information on code tags may be found at the link on my signature.
• 09-29-2002
try something like

Code:

```#include <iostream.h> #include <iomanip.h> int main() {   double pi = 3.14152;   cout.setprecision(3);   cout << pi; }```
• 09-30-2002
master5001
Does kermi3 really exist? I mean I am having deja vu here I saw the same post on another thread! Ah what is this world going to?

kermi, there is no need to dignify this post with a response I am just kidding.
• 09-30-2002
icarus
Quote:

mean I am having deja vu here I saw the same post on another thread!
Uhh oh. We all knows what means...a glitch in the matrix!
• 09-30-2002
kermi3
:)

...Ands someone's watching too much Fox.
• 09-30-2002
swoopy
>i have to get calculations using double and float.
Then declare your variables as double or float.

double pi1, pi2, x=-1.0, var;
int count;

In your calculation, to do multiplication, use *.
Also you need to initialize both count and var.