Thread: Why Do I keep Getting this Error Message?

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    15

    Why Do I keep Getting this Error Message?

    Hi, so im trying to write a program in C that solves for the 2 roots of a quadratic equation.

    However I keep getting these errors:
    cpp(13) : error C2064: term does not evaluate to a function taking 1 arguments
    cpp(14) : error C2064: term does not evaluate to a function taking 1 arguments

    My code is...

    Code:
    #include <stdio.h>
    int main()
    {
    int a,b,c,d,sqrt;
    float root1,root2;
    printf("Enter A:");
    scanf("%d%d%d",&a);
    printf("Enter B:");
    scanf("%d",&b);
    printf("Enter B:");
    scanf("%d",&c);
    d=b*b-4*a*c;
    root1=((-b)+sqrt(d))/(2*a);
    root2=((-b)-sqrt(d))/(2*a);
    printf("root1=%f & root2=%f",root1,root2);
    }

    BTW, Line 13 and 14 are the ones with the "root1=((-b)+sqrt...etc"

    So, can someone please help me with what is wrong?
    Thanks

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    It isn't going to understand "(-b)" ...

    You need to convert b to a negative number by other means.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Nothing595
    BTW, Line 13 and 14 are the ones with the "root1=((-b)+sqrt...etc"

    So, can someone please help me with what is wrong?
    The problem lies earlier:
    Code:
    int a,b,c,d,sqrt;
    You declared sqrt to be an int variable, and then you tried to call it as if it were a function. But of course, you actually do want the function. As such, remove the declaration of sqrt from that line and #include <math.h> instead.

    Incidentally, you made another mistake on this line:
    Code:
    scanf("%d%d%d",&a);
    Quote Originally Posted by CommonTater
    It isn't going to understand "(-b)" ...

    You need to convert b to a negative number by other means.
    That is not true. (-b) is perfectly fine.
    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

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by laserlight View Post
    That is not true. (-b) is perfectly fine.
    Well, I'll be... ya' learn something new everyday!

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    15
    I fixed that, but now I get an error message that says " cpp(15) : error C2668: 'sqrt' : ambiguous call to overloaded function"

    My current code is
    Code:
    #include <stdio.h>
    #include "math.h"
    int main()
    {
    int a,b,c,d;
    float root1,root2;
    printf("Enter A:");
    scanf("%d",&a);
    printf("Enter B:");
    scanf("%d",&b);
    printf("Enter B:");
    scanf("%d",&c);
    d=b*b-4*a*c;
    root1=((-b)+sqrt(d))/(2*a);
    root2=((-b)-sqrt(d))/(2*a);
    printf("root1=%f & root2=%f",root1,root2);
    }

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Switch to use a C compiler instead of a C++ compiler.

    By the way, you should indent your code properly.
    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

  7. #7
    Registered User
    Join Date
    Sep 2010
    Posts
    15
    So Microsoft Visual C/C++ Express Edition 2008 won't work for it?

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It probably can, if you configure it, or simply change the file extension to ".c".
    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

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Or simply declare d as a float also.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #10
    Registered User
    Join Date
    Dec 2008
    Posts
    15
    I think that you should declare: d, root1,root2 as variable type double for more accuracy. Also, the function sqrt() returns a variable type of double.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Why Do I keep Getting this Error Message?
    << Because you keep trying to compile that program! >>


    Sorry, could not resist.

Popular pages Recent additions subscribe to a feed