My PI program

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 03-31-2002
marcusbankuti
My PI program
Somebody please help me with this. In the last 5 mins. or so, I've been trying to write a program that just shows digits in pi. I have the formula for it (1/2.545584412*8).

Here is my code. Whenever I execute it, it just shows 575 and terminates.

#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

int main()
{
int pi;
{
pi==1/2.545584412*8;
cout << pi;
}
return 0;
}

• 03-31-2002
SilentStrike
pi==1/2.545584412*8;

This should be

pi=1/2.545584412*8;

You want to assign pi to that value, not test for equality.
• 03-31-2002
marcusbankuti
Quote:

Originally posted by SilentStrike
pi==1/2.545584412*8;

This should be

pi=1/2.545584412*8;

You want to assign pi to that value, not test for equality.

Now it says 3 and terminates. Why no decimal numbers? What am I missing?
• 03-31-2002
Shiro
The problem is you defined pi as an int.
• 03-31-2002
marcusbankuti
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

int main()
{
int pi;
{
cout << 1/2.545584412*8;
system("pause");
}
return 0;
}

That is my new code. Now, it shows only 3.1427, how do I get it do display more digits? Also, when beside the equation, I take away the ;, and << /n;, the program does not run, and when it is <<"/n";, It does not work.
• 03-31-2002
xlnk
define pi as 'double' not 'int'
Code:

```#include <iostream.h> #include <stdlib.h> #include <string.h> #include <conio.h> int main() {     double pi = 1/2.545584412*8;       cout << pi;     system("pause");     return 0; }```
• 03-31-2002
marcusbankuti
Same outcome. only 4 digits after .
• 03-31-2002
xlnk
Code:

```#include <iostream.h> #include <stdlib.h> #include <string.h> #include <conio.h> #include <iomanip.h> int main() {         setprecision(n);  // where 'n' is how many decimal places you want     double pi = 1/2.545584412*8;          cout << pi;     system("pause");     return 0; }```
• 03-31-2002
marcusbankuti
Quote:

Originally posted by xlnk
Code:

```#include <iostream.h> #include <stdlib.h> #include <string.h> #include <conio.h> #include <iomanip.h> int main() {         setprecision(n);  // where 'n' is how many decimal places you want     double pi = 1/2.545584412*8;          cout << pi;     system("pause");     return 0; }```

Still only 4 digits.
• 03-31-2002
xlnk
Code:

```#include <iostream.h> #include <stdlib.h> #include <string.h> #include <conio.h> #include <iomanip.h> int main() {         cout << setprecision(8);      double pi = 1/2.545584412*8;          cout << pi;     system("pause");     return 0; }```
sorry i forgot to tell you to put it in a cout statement.
• 03-31-2002
Linette

:D
• 03-31-2002
xlnk
what can i say, im fast :cool:
• 03-31-2002
marcusbankuti
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <iomanip.h>

int main()
{
int a;
cout << setprecision(250);

double pi = 1/2.545584412*8;
cout << pi;
cout << "\n";
system("pause");
return 0;
}

Why do only 50 digits or so come up?
• 03-31-2002
xlnk
the range for 'double' is 1.7e + / - 308 (15 digits)
for 'long double its 1.2e + / - 4932 (19 digits)
• 03-31-2002
marcusbankuti
Quote:

Originally posted by xlnk
the range for 'double' is 1.7e + / - 308 (15 digits)
for 'long double its 1.2e + / - 4932 (19 digits)

Changing from double to long double did not help.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last