I am getting an Undefined reference to <function>, here is my code:
Code:
#include <stdio.h>
#include "qsolver.h"
int main() {
double a, b, c, x1, x2;
int qret;
while(1) {
printf("Enter variables for quadratic equation (type: \n");
scanf("%lf %lf %lf", &a, &b, &c);
if((qret = qsolver(a, b, c, &x1, &x2)) != 0) {
printf("Error Value: %d\n", qret);
}
}
return 0;
}
******************************************************************************
#include <stdio.h>
#include <math.h>
#include "qsolver.h"
int qsolver(double a, double b, double c, double* x1, double* x2) {
//Is the user giving an input which would divide by zero?
if(a == 0) {
printf("Input Not A Quadratic; Cannot Have Value Of '0' For A\n");
return 1;
}
//Is the user giving and input which would try to compute a square root of a negative number.
else if( (4*a*c) > pow(b,2) ) {
printf("There Are No Real Solutions; B^2 Is Less Than (4*A*C)\n");
return 2;
}
//The user input is valid, solve accordingly
else {
*x1 = (-b + sqrt(pow(b,2) - (4*a*c)))/(2*a);
*x2 = (-b - sqrt(pow(b,2) - (4*a*c)))/(2*a);
return 0;
}
}
*****************************************************************************************
#ifndef QSOLVER_H
#define QSOLVER_H
int qsolver(double, double, double, double *, double *);
#endif