I tried to call the function "calculate_distance" from the file calculus.cpp in my main program "calculator.cpp". But whenever I do that, I get the error "undefined reference to calculate_distance".
The function uses call by reference, and I don't know if that has something to do with the error, or if I imported something wrong. Maybe I messed something with the reference up?
Could someone please help me with my code?
calculus.cpp:
#include "calculus.h"
#include <cmath>
int calculate_distance(double a, double v_max, double t, double& l, double& v_end) {
l = 0;
v_end = 0;
l = 0.5 * a * pow(t, 2);
v_end = sqrt(2 * a * l);
return 0;
}
calculus.h:
#ifndef CALCULUS_H
#define CALCULUS_H
int calculate_distance(double a, double v_max, double t, double& l, double& v_end);
#endif
calculator.cpp:
#include <iostream>
#include "/workspaces/20230324_sew_ex03_functions-Schwotz_Scherko/src/libraries/Calculus/calculus.h"
using std::cout;
using std::cin;
using std::endl;
double acceleration = 0;
double maximum_velocity = 0;
double time_length = 0;
double length = 0;
double velocity_end = 0;
int main() {
cout << "Please input the uniform acceleration a: ";
cin >> acceleration;
cout << "Please input the maximum velocity v_max: ";
cin >> maximum_velocity;
cout << "Please enter the time t: ";
cin >> time_length;
calculate_distance(acceleration, maximum_velocity, time_length, length, velocity_end);
cout << "--------------------------------------------------------------------------------" << endl;
cout << "INPUTS:" << endl;
cout << "--------------------------------------------------------------------------------" << endl;
cout << "a= " << acceleration << endl;
cout << "v_max= " << maximum_velocity << endl;
cout << "t= " << time_length << endl;
cout << "--------------------------------------------------------------------------------" << endl;
cout << "RESULTS:" << endl;
cout << "--------------------------------------------------------------------------------" << endl;
cout << "l= " << length << endl;
cout << "v_end= " << velocity_end << endl;
cout << "--------------------------------------------------------------------------------" << endl;
cout << "Quit? [y/n]: ";
}