## SurviBee

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;

else
{
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);

x=dx/d;
y=dy/d;
z=dz/d;
cout << "X = " << x << " Y = " << y << " Z = "  << z;
cin.get();
cin.get();
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;
}

## Ancient Dragon 5,243

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.

## Narue 5,707

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

## iamthwee 1,547

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.

## Narue 5,707

>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.

## iamthwee 1,547

I'm not sure what the requirements of the assignment is, so yes the problem may require a hard coded solution for that specific example.

Presumably they want to obtain the determinant to solve the system of equations.
http://www.maths.surrey.ac.uk/explore/emmaspages/option1.html

x = A^{-1}b

where