C++ computation not working

This is a discussion on C++ computation not working within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm new to this forum and i'm looking for a bit of help specifically with one line out of ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    2

    C++ computation not working

    Hi, I'm new to this forum and i'm looking for a bit of help specifically with one line out of 3255.
    Code:
    Rf = 0.027*(pow(E,(1/3)));
    this always returns 0.027 no matter what the value of E is there a way round this or have i done something wrong?

  2. #2
    Registered User
    Join Date
    May 2005
    Location
    Sweden
    Posts
    16
    The problem is that 1/3 is interpreted as integer arithmetic by your compiler. 1/3 with integers is 0 and anything raised to the power of 0 is 1. So basically, your code says:
    Code:
    Rf = 0.027*1
    To tell the compiler you want floating points, use 1.0 and 3.0 or cast the values.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    I suspect it's 1/3 returning an integer value of zero. Try 1.0/3.0 .

    EDIT - ...Looks like Kenki beat me to it.
    Last edited by DougDbug; 05-18-2005 at 01:06 PM.

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    2
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 04:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 08:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 05:08 AM

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