Was compiling homework problem with Dev-C++ and got
]Linker Error] undefined reference to determinant(float, float, float, float, float, float, float, float, float)
Anyone know what this is?

#include <iostream>
using namespace std;

float determinant(float, float, float, float, float, float, float, float, float);

int main()
    float x1, x2, x3, y1, y2, y3, z1, z2, z3, c1, c2, c3; //unknowns
    float dx, dy, dz, d; //determinants
    float x, y, z; //results
    cout << "This program will solve a system of equations with three variables."  << endl;
    cout << "Please enter the system one at a time and in order like so: x y z c" << endl;
    cout << "x  y  z  c" << endl;
    cin >> x1 >> y1 >> z1 >> c1;
    cin >> x2 >> y2 >> z2 >> c2;
    cin >> x3 >> y3 >> z3 >> c3;
    cout << "Are these correct? :";
    char response;
    cin >> response;
    if (response=='n')
    return 0;
        cout << "Dx = ";
    dx=determinant(c1, c2, c3, y1, y2, y3, z1, z2, z3);
        cout << endl << "Dy = ";
    dy=determinant(x1, x2, x3, c1, c2, c3, z1, z2, z3);
    cout << endl << "Dz = ";
    dz=determinant(x1, x2, x3, y1, y2, y3, c1, c2, c3);
    cout << endl << "D = ";
    d=determinant(x1, x2, x3, y1, y2, y3, z1, z2, z3);
    cout << "X = " << x << " Y = " << y << " Z = "  << z;
    return 0;

float determinant(float x1,float  x2,float  x3,
                         float  y1,float  y2,float  y3,
                         float  z1,float  z2,float  z3,
                         float  c1,float  c2,float  c3)  
              float determinantval= x1*(y2*z3-y3*z2) 
                                              - x2*(y1*z3-y3*z1)
                                              + x3*(y1*z2-y2*z1);
              cout << determinantval;
              return determinantval;
9 Years
Discussion Span
Last Post by SurviBee

count the arguments -- the function at the bottom of your code has 12 arguments but the function prototype at the top has only 9 arguments -- they are not he same function.


>Anyone know what this is?
The number of parameters don't match between the function declaration and definition for determinant.


Another point worth mentioning is the flexibility of your function. In other words it isnt'. Programming should be about handling the general case. For example the way you have x1,x2 and x3 flipping from '+' to '-' could be done using the modulus operator. Which is often used to identify even or odd numbers.

And use doubles instead of floats.


>Programming should be about handling the general case.
Not always. If you write libraries for general use then definitely. If you write applications, it's often better[1] to be as specific as possible within the constraints of good design[2].

[1] Read this as more productive, faster, more efficient, and cheaper. If you spend time and money preparing for all of the "potential" cases, you write yourself into a complicated mess.

[2] Of course, you should include hooks for likely updates and maintenance to the code. There's naturally a fine balance between simplicity and generality that a lot of people fail to hit because they're trying to K.I.S.S. or handle the general case. "As simple as possible, but no simpler" is the vague quote of the day for this topic.


Yes, im solving a system of equations, totally overlooked number of arguments thank you.
I'd use an array to pass the numbers to the function but we haven't gotten that far and I have only a rudimentary understanding of how to implement that sort of thing.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.