Noorez,
Just a suggestion to your algorithm in
order to not use an "if/else" statement.
<snip>
const double numerator = 4;
double PI = 4; // short, signed or unsigned invalid for PI.
// The only modifier you can use is "long" with "double"
// bool add = false;
short int sign = 1; //set a variable to act as a sign
cout << "Running..." << endl;
for(double i = 3; i < 999999999; i+=2){
sign *= -1; //switches the "sign" on each iteration
PI += ((numerator/i)*sign);
}
</snip>
Regards,
Rafael Charnovscki
"Alfred P. Reaud" wrote:
>
> Hi Noorez,
>
> Is there such a thing as an unsigned double? IMHO, floats and doubles
> ...................
> int main(int argc, char *argv[])
> {
> const double numerator = 4;
> double PI = 4; // short, signed or unsigned invalid for PI.
> bool add = false;
> cout << "Running..." << endl;
> for(double i = 3; i < 999999999; i+=2)
> {
> if( add )
> {
> PI += numerator/i;
> add = false;
> }
> else
> {
> PI -= numerator/i;
> add = true;
> }
> }
> cout << setprecision(15) << PI << endl << endl;
> system("PAUSE");
> return EXIT_SUCCESS;
> }
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.0 - Release Date: 29/04/05
|