function problem

This is a discussion on function problem within the C++ Programming forums, part of the General Programming Boards category; Hi, What is wrong with this function? Code: float distance3(float 1px, float 1py, float 1pz, float 2px, float 2py, float ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91

    function problem

    Hi,
    What is wrong with this function?

    Code:
    float distance3(float 1px, float 1py, float 1pz, float 2px, float 2py, 
                float 2pz)
    {
    	float dist = 0.0f;
    	float dist = sqrt(((2px - 1px)(2px - 1px)) + ((2py - 1py)(2py - 1py)) +   
                    ((2pz - 1pz)(2pz - 1pz)));
    	return dist;
    }
    Error is:
    error C2064: term does not evaluate to a function taking 1 arguments
    Any help will be great. Thanks!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,623
    Did you #include <cmath> for sqrt()?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,664
    Doesn't
    Code:
    ((2px - 1px)(2px - 1px))
    need to be
    Code:
    ((2px - 1px)*(2px - 1px))
    ?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,623
    hmm... yeah, I think rags_to_riches' diagnosis is more accurate.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91
    Did you #include <cmath> for sqrt()?
    Yes, I did..

    Doesn't

    Code:
    ((2px - 1px)(2px - 1px))need to be

    Code:
    ((2px - 1px)*(2px - 1px))?
    Thanks guys, I think that solved the problem..

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    	float dist = 0.0f;
    Wouldn't that be a tad redundant when you declare another variable by the same name another line below?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91
    Wouldn't that be a tad redundant when you declare another variable by the same name another line below?
    Yes, I actually edited it. Thanks, matsp.

    Code:
    float distance3(float 1px, float 1py, float 1pz, float 2px, float 2py, 
                float 2pz)
    {
    	return sqrt(((2px - 1px)(2px - 1px)) + ((2py - 1py)(2py - 1py)) +   
                    ((2pz - 1pz)(2pz - 1pz)));
    }

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What is "2px" even supposed to be? Variable names can't start with numbers.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-29-2008, 06:33 AM
  2. wxWidgets link problem
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 01:36 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM

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