Thread: Weird bug ?

  1. #1
    Registered User
    Join Date
    Jun 2007

    Weird bug ?

    I made a progam to calculate the surface of a cirkel. But when i open it, and a give the dia meter and press enter, the progam close. This is the code;
    #include <stdio.h>
    #define PI 3.14
    int main()
    int diameter;
    double straal;
    double oppervlakte;
    printf("Geef de diameter van de cirkel:\t");
    scanf("&#37;d", &diameter);
    straal = diameter / 2;
    oppervlakte = PI * (straal * straal);
    printf(" De oppervlakte is \t%d", oppervlakte);
    return 0;
    (don't look at the dutch words)
    Do you know a solution?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    1. diameter / 2 uses integer division - I don't think you want it
    2. printf(" De oppervlakte is \t&#37;d", oppervlakte);

    oppervlakte is double - suitable format for printf is %f

    3. See the FAQ why the Window of the program will close on exit and how to prevent it - for example run it from the command prompt
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    A little bit of indenting wouldn't hurt either

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Surely you can find a more accurate value for pi. From memory, pi is 3.14159265358979. Even typing "pi" into google gives you 3.14159265.

    And if you want lots of digits, go here:

    Note that over fifteen or twenty digits is overkill because that's what a double is accurate to.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird bug in the scanf command
    By transgalactic2 in forum C Programming
    Replies: 13
    Last Post: 10-24-2008, 03:26 PM
  2. Debugging a rare / unreproducible bug..
    By g4j31a5 in forum A Brief History of
    Replies: 18
    Last Post: 08-05-2008, 12:56 PM
  3. ATL bug of CComPtr?
    By George2 in forum Windows Programming
    Replies: 6
    Last Post: 04-07-2008, 07:52 AM
  4. Weird bug
    By Hunter2 in forum Windows Programming
    Replies: 1
    Last Post: 08-12-2002, 03:45 PM
  5. Weird bug in the forum
    By SilentStrike in forum A Brief History of
    Replies: 2
    Last Post: 01-16-2002, 06:16 AM