// 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);
pi = 1/a;
cout << "Pi = " << pi;
return 0;

please correct my mistakes. i am tired

Votes + Comments
Shape up or ship out. :(
6 Years
Discussion Span
Last Post by Sokanas

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

Edited by Fbody: n/a


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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.