integer Count doesn't increment properly, doesn't work with GCC, but does with CC

This is a discussion on integer Count doesn't increment properly, doesn't work with GCC, but does with CC within the C Programming forums, part of the General Programming Boards category; Hi there. I am trying to write a program that approximates the integral of Cos^2, by working out the area ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    14

    integer Count doesn't increment properly, doesn't work with GCC, but does with CC

    Hi there.
    I am trying to write a program that approximates the integral of Cos^2, by working out the area under the graph.

    It was working on my home computer, running OSX, using GCC to compile, although I gather that GCC and CC are the same thing on OSX.

    But, trying to run it on my university computers (Unix) I get some crazy things happening, which seem to be caused by an issue with incrementing an integer.

    The code is here.

    When I compile with GCC, I get this as my output:
    Code:
    Count = 3555 
    Count = 3556 
    Count = 3557 
    Count = 3558 
    Count = 3559 
    Count = 3560 
    Count = 3561 
    Count = 3562 
    Count = 3563 
    Count = 3564 
    Count = 3565 
    Count = 3566 
    Count = 3567 
    The integral of (Cos(x))^2 between 0.000000 and 0.560000 is -22451877030849596034839243233979729137634606950168132554244772637725918156767371541383682094482259477193717530871408213064495352486659616158821156590299808112573904456113502043764019515866649496876255051482750237449798387798526542402632640838500465932172585681913451504091616968612989814208112571000503140352.000000
    But using CC, I get this:
    Code:
    Count = 3560 
    Count = 3561 
    Count = 3562 
    Count = 3563 
    Count = 3564 
    Count = 3565 
    Count = 3566 
    Count = 3567 
    The integral of (Cos(x))^2 between 0.000000 and 0.560000 is 0.505039
    Which is close enough to the right answer. But, changing
    Code:
    printf("Count = %d \n",count);
    to
    Code:
    printf("Count = %d \n",count);
    I get:
    Code:
    Count = 7.5543e-311 
    Count = 7.55642e-311 
    Count = 7.55855e-311 
    Count = 7.56067e-311 
    Count = 7.56279e-311 
    Count = 7.56491e-311 
    Count = 7.56703e-311 
    Count = 7.56916e-311 
    Count = 7.57128e-311 
    The integral of (Cos(x))^2 between 0.000000 and 0.560000 is -22451705589472446232067891485971879537344917125398259668867581637663778900599191551604083182741648965856417115723741404561003322543413905388574180837058612935377041503029104856068252778672968498937985004215835788706198650487466264022351694189797328699165952542769808519416934401735683372217923175709814030336.000000
    Unfortunately for me, the code is compiled with GCC when marked
    What on earth is going on?
    Thanks for the help

  2. #2
    Registered User
    Join Date
    Dec 2010
    Posts
    14
    Argh sorry stupid mistake - solved it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-08-2010, 06:25 PM
  2. trying to get a few functions to work properly...
    By lemonwaffles in forum C++ Programming
    Replies: 3
    Last Post: 07-16-2009, 12:00 AM
  3. Why this program doesnt work properly
    By enggabhinandan in forum C Programming
    Replies: 12
    Last Post: 10-21-2006, 05:12 AM
  4. Can't Get This Program To Work Properly
    By jbyers19 in forum C Programming
    Replies: 5
    Last Post: 03-09-2006, 10:59 PM
  5. Exactly what do I need to reinstall to ensure Java will work properly with my browser
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 11-09-2002, 07:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21