Results 1 to 4 of 4

Thread: Anyone know C++?

                  
   
  1. #1
    DCEmu Regular Nicko01's Avatar
    Join Date
    Jun 2006
    Location
    www.nicko01.com
    Age
    32
    Posts
    434
    Rep Power
    73

    Default Anyone know C++?

    Hello. I was bored and decided to make a program for windows to calculate pi, but its not working...


    ok, heres what i wrote:

    Code:
    #include <iostream>
    int main()
    {
    using namespace std;
    long double pi;
    unsigned long int denom;
    bool subtract;
    denom = 1;
    subtract = true;
    pi = 4;
    while(true)
    {
               cout << pi;
               cout << "\n";
               if (subtract == true)
               {
                  denom = denom + 2;
                  pi = pi-4/denom;
                  subtract = false;
               }
               else
               {
                  denom = denom + 2;
                  pi = pi+4/denom;
                  subtract = true;     
               }
               
    }
    
    return 0;
    }
    it just prints out 3 repeatedly!
    it seems like it's rounding off everything. Is there any way I can stop this from happening and can anyone tell me WHY this is happening?

    I dont really need it for calculating pi, i have around 90 digits memorized
    I just need to work on my programming skills....
    thats the whole reason for this program.
    (please dont just read this and then hit the back button without saying something)

  2. #2
    Dreamcast User gdf's Avatar
    Join Date
    Aug 2006
    Location
    Hyperspace
    Posts
    1,704
    Rep Power
    134

    Default

    i don't know.
    check it against tuts here- http://www.cprogramming.com/tutorial.html

  3. #3
    CONSOLE HOARDER VampDude's Avatar
    Join Date
    Aug 2006
    Location
    Seinan Eikoku
    Posts
    5,499
    Blog Entries
    4
    Rep Power
    135

    Default

    I know some C++, but not enough to actually help anyone...

    ...Oh and your code is horrible!

  4. #4
    Dream Coder
    Join Date
    Apr 2004
    Location
    Miami, FL
    Age
    38
    Posts
    4,675
    Rep Power
    50

    Default

    make both pi and denom an unsigned long double, or just add a .0 to the end of the 4. The problem is that it's getting turned back into an int because it thinks it doesn't need the precision.
    If anyone is looking to buy, sell, trade games and support a developer directly at the same time, consider joining Goozex. Enjoy!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •