Why Do I keep Getting this Error Message?

This is a discussion on Why Do I keep Getting this Error Message? within the C Programming forums, part of the General Programming Boards category; Hi, so im trying to write a program in C that solves for the 2 roots of a quadratic equation. ...

  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
    20,954
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    20,954
    Switch to use a C compiler instead of a C++ compiler.

    By the way, you should indent your code properly.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    20,954
    It probably can, if you configure it, or simply change the file extension to ".c".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,261
    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

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