Re: Computing pi to nth terms?
From: Kraig (tsi1990_at_gmail.com)
Date: 09/19/04
- Next message: Francis Glassborow: "Re: google "top coder" contest = stacked against C++ coders"
- Previous message: Dai Kane: "error: no match for 'operator>' ..."
- In reply to: George: "Re: Computing pi to nth terms?"
- Next in thread: John Harrison: "Re: Computing pi to nth terms?"
- Reply: John Harrison: "Re: Computing pi to nth terms?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
>
>
- Next message: Francis Glassborow: "Re: google "top coder" contest = stacked against C++ coders"
- Previous message: Dai Kane: "error: no match for 'operator>' ..."
- In reply to: George: "Re: Computing pi to nth terms?"
- Next in thread: John Harrison: "Re: Computing pi to nth terms?"
- Reply: John Harrison: "Re: Computing pi to nth terms?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|