// Cubic conversion of Borwein's Algorithm
// Each iteration converges
// cubically against 1/pi;
// that is, each iteration
// approximately triples the
// number of correct digits.
// Program written by ROBO_HEN5000
// Algorithm complements of Wikipedia.
 


#include <iostream>
#include <cmath>
 
using namespace std; 
int main()
{
float a;
double pi;
double s;
double r;
double k;
int iterations;
int repetitions = 0;
cout << "How many iterations of the equation would you like? \n";
cout << "The first iteration yields 3.14.\nEach iteration triples the number of correct digits.";
cin >> iterations;
cout << "\nCalculating Pi...\n";
 
s = (sqrt(3)-1)/2;
a = 1.0/3;
while (iterations >= repetitions)
{
r = 3/(1+2*pow((1-pow(s,3.0)),(1/3)));
s = (r-1)/2;
a = pow(r,2)*a-pow(3,k)*(pow(r,2)-1);
repetitions++;
};
pi = 1/a;
cout << "Pi = " << pi;
return 0;
}

please correct my mistakes. i am tired

Fbody commented: Shape up or ship out. :( -1

Recommended Answers

All 4 Replies

>>i am tired
As are we, of you trying to cheat your way through your class. DO YOUR OWN HOMEWORK.

Post all your mistakes. Maybe we can help.

You should use whitespace.

You initialize variable k for one, you have posted this same problem on several forums.
And seeing as your variables are doubles (mostly) you should be typecasting or using .0 on the end of them.

e.g. double a = 3 wont work. double a = 3.0 will!
as will (double)3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.