I'm trying to use a struct to output two values from a function to then be used in the main. I am using a header file to call the functions to be used. The code is compiling but the values I'm getting are not correct. I don't know if I'm declaring the struct correct in my .h file or where something is getting used incorrectly. At the moment, my .h file looks like:
#ifndef LINEAR_DISPERSION_SOLVER_H #define LINEAR_DISPERSION_SOLVER_H //Function for dispersion relation equation double f (double L, double T, double g, double d); //Function for derivative of linear dispersion relation double df(double L, double T, double g, double d); //Wave parameter struct definition struct wave_parameters { double kn; double w; }; //Linear Dispersion Solver function wave_parameters linear_dispersion(); #endif And a portion of my .cpp (not main) looks like:
#include <iostream> #include <cstdlib> #include <cmath> #include <iomanip> using namespace std; struct wave_parameters { double kn; double w; }; float pi = 3.1415927; double f(double L, double T, double g, double d) { return (g*g); } double df(double L, double T, double g, double d) { return (1 + ((g*T*T*d)/(L*L)) } struct wave_parameters linear_dispersion () { .... Deleted code ..... int choice; cout << "Enter the depth of water ---> "; cin >> d; cout << "Enter 1 to solve for wave number or 2 to solve for frequency --> "; cin >> choice; //Calling the wave struct to fill with values struct wave_parameters wave; if (choice == 1) { cout << "Enter the value for period ---> "; cin >> T; .... Deleted code .... wave.kn = k; wave.w = omega; return wave; } My main then includes the .h file and calls the .cpp file using:
struct wave_parameters wave; kn = wave.kn; Is this the correct method to outputting multiple variables and then using a header file? As you can see, I've declared my struct twice (once in my .h and once in my .cpp file) but I was doing this as i was getting errors otherwise. Any help is really appreciated!