Re: Computing pi to nth terms?

From: Kraig (tsi1990_at_gmail.com)
Date: 09/19/04


Date: Sun, 19 Sep 2004 12:21:10 -0500

That's where I got lost, on the #define part. I had, to no avail:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
        float fCalcPI = 0;
        float fTerms = 0;

        cout << "Enter number of terms.\n";
        cin >> fTerms;

        fCalcPI = fTerms - (fTerms/3) + (fTerms/5) - (fTerms/7) + (fTerms/9) -
(fTerms/11);

        cout << "Pi is " << fCalcPI << " \n";

        return 0;
}

Like I said, I'm learning as I go. Please be patient :)

kraig

George wrote:
> "George" <clarkgsmith@comcast.net> wrote in message
> news:H_6dnV038cTfNNHcRVn-vQ@comcast.com...
>
>>"Kraig" <tsi1990@gmail.com> wrote in message
>>news:zmM2d.173745$%n4.92688@bignews6.bellsouth.net...
>>
>>>Hi! I'm new to programming and am trying to figure out the best way
>>>using loops, to compute pi to say, 14 terms using values that double each
>>>time through the loop. As in, from 1-2-4-8-16, et al. I'm at a loss as
>>>to where to start. Does anyone have any ideas how to do this? Thanks for
>>>any help you can provide.
>>>
>>>kraig
>>
>>#define PI 3.14159
>>
>>double total = 0;
>>unsigned char i;
>>
>>for(i=0; i<14; i++)
>> total *= PI;
>
>
> but then, that would result in total == 0.
>
> maybe double total = PI:
>
> you will have to finish the assignment yourself sir.
>
> regards
>
>



Relevant Pages

  • Re: Visual C++ vs Visual C#
    ... idea of learning C++ without learning C to be fraught with the same ... int main ... using namespace std; ... We've added namespaces and shift operators for no gain, ...
    (microsoft.public.vc.language)
  • Re: Some Advice.
    ... > int main{ ... Yes I am learning that and and implementing as I go along. ... you should provide inclusion guards for headers. ... > function definitions into separate source files. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: input and output questions about file
    ... using namespace std; ... junk.c:5: warning: type defaults to `int' in declaration of `std' ... junk.c:10: `string' undeclared ... junk.c:12: parse error before '/' token ...
    (comp.lang.c)
  • Re: Comparing files (Fast)
    ... I didn't knew what is was, but using fseek solved the problem. ... I'm using a timer utility Scott Meyers wrote for use ... > using namespace std; ... > int ch1,ch2; ...
    (comp.lang.cpp)
  • Re: return memory to the OS
    ... > 4 using namespace std; ... > 5 int main ... > possible to make STL return this memory to the OS (say using a system ... :: "out of confusion comes chaos -- out of chaos comes confusion and fear ...
    (comp.lang.cpp)