How do I use mathematical operators?

This is a discussion on How do I use mathematical operators? within the C++ Programming forums, part of the General Programming Boards category; I want to use math functions as pow and sqrt. When i try to do that (including math.h) I get ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    10

    How do I use mathematical operators?

    I want to use math functions as pow and sqrt.

    When i try to do that (including math.h) I get an error msg saying that these operator are double and i'm performing a calculation with integers

    Any ideas?
    Pana8hnaikos The Pride Of Greece

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    You could try following the advice of the errors. Either declare the variables that you want to use the math functions on as double, or cast the result of the functions to int, like so:
    Code:
    int x = 256, result;
    
    result = (int)sqrt(x);
    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    10
    Thx man

    I used casting as

    int x;
    double approx_x;
    approx_x=double(x);

    Thanks
    Pana8hnaikos The Pride Of Greece

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Operators in C++
    By Flecto in forum C++ Programming
    Replies: 4
    Last Post: 05-15-2009, 07:17 AM
  2. Bolean Operators hurt my head. (Trouble understanding) :(
    By Funcoot in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2008, 06:42 PM
  3. bitwise and arithmetic Operators
    By Whiteghost in forum C Programming
    Replies: 4
    Last Post: 12-28-2006, 01:13 PM
  4. operators???
    By arjunajay in forum C++ Programming
    Replies: 11
    Last Post: 06-25-2005, 04:37 AM
  5. Operators
    By George in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2003, 06:35 PM

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