I have two pieces of code:

Code:
#include <cmath>;
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <armadillo>
using namespace arma;
using namespace std;




inline void n1234(int nodes, int ny, int nx, double ly, double lx, Mat<int>& N, int l){
	for (int i = 0; i<nodes; i++){
		N(i, 0) = ly*((int)(i/ny));
		N(i, 1) = lx*(i-ny*((int)(i/ny)));
	}
	for (int i = 1*(ny-1)/3; i<1+2*(ny-1)/3; i++) {
		N(i, 2) = 1;
		N(i, 3) = 1;
	}
	N((nx-1)*ny+(ny-1)/2, 5) = -l;
	return;
}




inline void doff(vec& dof, int nodes, Mat<int>N){
	dof(0) = 1;
	dof(nodes) = 1;
	for (int i = 0; i<nodes; i++){
		if (i>=1){
			dof(i) = (1-N(i, 2))+dof(i-1);
			dof(i + nodes) = (1-N(i, 3))+dof(i+nodes-1);
		}
	}
	for (int i = 1; i<nodes; i++){
		if (N(i, 2) == 1){
			dof(i) = 0;
		}
		if (N(i, 3) == 1){
			dof(i+nodes) = 0;
		}
	}
	for(int i = 0; i<nodes; i++){
		if (dof(i+nodes) != 0){
			dof(i+nodes) += dof(nodes-1);
		}
	}
	return;
}





inline void PCLf1(int elems, int nodes, mat& PCL){
	vec N11(elems);
	vec N22(elems);
	mat N1(nodes, nodes);
	mat N2(nodes, nodes);
	int ka = 0;
	int kb = 0;
	for (int i = 0; i<nodes; i++){
		for (int k = 0; k<nodes; k++){
			N1(i, k) = k+1;
			N2(i, k) = i+1;
			if (k>=i){
				N1(i, k) = 0;
				N2(i, k) = 0;
			}
		}
	}
	for (int i = 0; i<nodes; i++){
		for (int k = 0; k<nodes; k++){
			if (N1(k, i) > 0){
				N11(kb) = N1(k, i);
				kb++;
			}
			if (N2(k, i) > 0){
				N22(ka) = N2(k, i);
				ka++;
			}
		}
	}
	for (int i = 0; i<elems; i++){
		PCL(i, 0) = N11(i);
		PCL(i, 1) = N22(i);
	}
	return;
}



inline void PCLf2(int elems, int nodes, mat& PCL, Mat<int>N){
	mat Le(elems, 2);
	Le.zeros();
	for (int i = 0; i<elems; i++){
		Le(i, 0) = N(PCL(i, 0) - 1, 0) - N(PCL(i, 1) - 1, 0);
		Le(i, 1) = N(PCL(i, 0) - 1, 1) - N(PCL(i, 1) - 1, 1);
		PCL(i, 2) = sqrt(pow(Le(i, 0), 2) + pow(Le(i, 1), 2));
	}
	return;
}




inline void PCLf3(int elems, int nodes, mat&PCL, double lx, double ly, int& elem_no){
	double adjacent = 1.01*sqrt(pow(lx, 2)+pow(ly, 2));
	for (int i = 0; i < elems; i++){
		if (PCL(i, 2)<adjacent){
			PCL(i, 3) = 1;
			elem_no++;
		}
	}
}





inline void Ef(mat& E, mat PCL, int nodes, int elems){
	int kc = 0;
	for (int i = 0; i<elems; i++){
		if (PCL(i, 3) == 1){
			for (int k = 0; k<4; k++){
				E(kc, k) = PCL(i, k);
			}
			kc++;
		}
	}
}





void solverr(Mat<int>, mat, int, int, int, int, int, vec);
void MATtoARR(mat, double**&);
void ARRtoMAT(int, int, mat&, double**);
void VECtoARR(vec, double*&);


extern int linprog1(double**, int, double*, int, double*, int);


int main(){

	cout.precision(6);
	int stop;
	int H = 500;
	int B = 250;
	int nx = 3;
	int ny = 7;
	int l = 1;
	int sc = 275;
	int st = 275;
	int j = 2;
	const int nodes = nx*ny;
	const int elems = nodes*(nodes-1)/2;
	int elem_no = 0;
	double lx;
	double ly;
	double adjacent_distance;
	int addedmem = 0;
	int addedmem_no = 1;
	double disp_size[2];
	Mat<int> N(nodes, 8); // contains node x position, y position, marks supports, marks external loads
	vec dof(2*nodes); // cumulative list of  degrees of freedom
	mat PCL(elems, 4); // first node, second node, distance, accepted

	disp_size[0] = B + 20;
	disp_size[1] = H + 20;
	lx = B/(nx-1);
	ly = H/(ny-1);

	N.zeros();
	PCL.zeros();

	n1234(nodes, ny, nx, ly, lx, N, l); // function for creating N
	PCLf1(elems, nodes, PCL); // function for creating the first 2 elements of PCL
	doff(dof, nodes, N); // Degree of Freedom function
	PCLf2(elems, nodes, PCL, N); // function for 3rd element of PCL
	PCLf3(elems, nodes, PCL, lx, ly, elem_no); // function for 4th

	mat E(elem_no, 4); // active members of PCL

	Ef(E, PCL, nodes, elems); // function for E
	vec nono(N.n_rows);
	for (int i = 0; i< N.n_rows; i++){
		nono(i) = N(i, 0);
	}

	uvec nodes_no = find(nono > 0);

	solverr(N, E, st, sc, j, E.n_rows, nodes_no.size(), dof);

	cin >> stop;
}




void solverr(Mat<int>N, mat E, int st, int sc, int j, int elem_no, int nodes_no, vec dof){
	const double PI = 3.14159265359;
	vec X(elem_no*2); X.zeros();
	mat B(8*elem_no, 3); // sparse matrix
	double n1;
	double n2;
	int kB = 0;
	vec coordinate(2);
	mat sub_matrix(2, 2);
	for (int elem = 0; elem < elem_no; elem ++){
		n1 = E(elem, 0); // finds the first out of the pair of nodes
		n2 = E(elem, 1); // finds the second
		coordinate(0) = (N(n2 - 1, 0) - N(n1 - 1, 0))/E(elem, 2); // change in x over total change
		coordinate(1) = (N(n2 - 1, 1) - N(n1 - 1, 1))/E(elem, 2); // change in y over total change
		for (int i = 0; i<2; i++){
			for (double k = 0; k<2; k++){
				sub_matrix(i, k) = coordinate(i)*(1 - 2*cos(k*PI/2));
			}
		}
		if (sub_matrix(0, 0) != 0){
			B(kB, 0) = n1;
			B(kB, 1) = elem;
			B(kB, 2) = sub_matrix(0, 0);
			//B(n1, elem) = sub_matrix(0, 0);
			kB += 1;
			B(kB, 0) = n2;
			B(kB, 1) = elem;
			B(kB, 2) = -sub_matrix(0, 0);
			//B(n2, elem) = -sub_matrix(0, 0);
			kB += 1;
		}
		if (sub_matrix(1, 0) != 0){
			B(kB, 0) = n1 + nodes_no;
			B(kB, 1) = elem;
			B(kB, 2) = sub_matrix(1, 0);
			//B(n1 + nodes_no, elem) = sub_matrix(1, 0);
			kB += 1;
			B(kB, 0) = n2 + nodes_no;
			B(kB, 1) = elem;
			B(kB, 2) = -sub_matrix(1, 0);
			//B(n2 + nodes_no, elem) = -sub_matrix(1, 0);
			kB += 1;
		}
		if (sub_matrix(0, 1) != 0){
			B(kB, 0) = n1;
			B(kB, 1) = elem + elem_no;
			B(kB, 2) = sub_matrix(0, 1);
			//B(n1, elem + elem_no) = sub_matrix(0, 1);
			kB += 1;
			B(kB, 0) = n2;
			B(kB, 1) = elem + elem_no;
			B(kB, 2) = -sub_matrix(0, 1);
			//B(n2, elem + elem_no) = -sub_matrix(0, 1);
			kB += 1;
		}
		if (sub_matrix(1, 1) != 0){
			B(kB, 0) = n1 + nodes_no;
			B(kB, 1) = elem + elem_no;
			B(kB, 2) = sub_matrix(1, 1);
			//B(n1 + nodes_no, elem + elem_no) = sub_matrix(1, 1);
			kB += 1;
			B(kB, 0) = n1 + nodes_no;
			B(kB, 1) = elem + elem_no;
			B(kB, 2) = -sub_matrix(1, 1);
			//B(n2 + nodes_no, elem + elem_no) = -sub_matrix(1, 1);
			kB += 1;
		}
	}
	vec n3(N.n_rows);
	uvec n5;
	int n7;
	vec n4(N.n_rows);
	uvec n6;
	int n8;
	for (int i = 0; i< N.n_rows; i++){
		n3(i) = N(i, 2);
		n4(i) = N(i, 3);
	}
	n5 = find(n3>0);
	n6 = find(n4>0);
	n7 = n5.size();
	n8 = n6.size();
	for (int i = 0; i<B.n_rows; i++){
		if (B(i, 0) == n7){
			B.shed_row(i);
		}
		if (B(i, 0) == n8 + nodes_no){
			B.shed_row(i);
		}
	}
	int i = 0;
	do {
		if (B(i, 2) <= 0){
			B.shed_row(i);
			i--;
		}
		i++;
	} while (i<B.n_rows);
	for (int i = 0; i<B.n_rows; i++){
	}
	double** Barray = new double*[B.n_rows];
	MATtoARR(B, Barray);

	n5 = find(n3==0);
	n6 = find(n4==0);
	vec f(n3.size()*2);
	vec solverer(n3.size()*2);
	for (int i = 0; i<n3.size(); i++){
		f(i) = N(i, 4);
		f(i + n3.size()) = N(i, 5);
	}
	vec OBJ(elem_no*2);
	for (int i = 1; i<=elem_no; i++){
		OBJ(2*i-2) = 2*j + (E(i-1, 2)/st);
		OBJ(2*i-1) = 2*j + (E(i-1, 2)/sc);	
	}

	//cout << n3.size()*2 << "  " << elem_no*2 << "  " << B.n_rows << endl;

	double* farray = new double[f.size()];
	VECtoARR(f, farray);
	double* objarray = new double[OBJ.size()];
	VECtoARR(OBJ, objarray);

	linprog1(Barray, (int)B.n_rows, farray, (int)f.size(), objarray, (int)OBJ.size());
}
void MATtoARR(mat Matr, double**& Arre){
	for (int i = 0; i<Matr.n_rows; i++){
		Arre[i] = new double(Matr.n_cols);
		for (int k = 0; k<Matr.n_cols; k++){
			Arre[i][k] = Matr(i, k);
		}
	}
}
void VECtoARR(vec Vect, double*& Arre){
	for (int i = 0; i<Vect.size(); i++){
		Arre[i] = Vect(i);
	}
}
void ARRtoMAT(int rows, int cols, mat& Matr, double** Arre){
	for (int i = 0; i<rows; i++){
		for (int k = 0; k<cols; k++){
			Matr(i, k) = Arre[i][k];
		}
	}
}
and


Code:
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <glpk.h>
#include <armadillo>
using namespace std;
using namespace arma;

int linprog1(double** Barray, int rowsb, double* farray, int rowsf, double* objarray, int rowsobj) // rowsb = B.n_rows, 
{ glp_prob *lp;
int* ia = new int[1+rowsb];
int* ja = new int[1+rowsb];
double* ar = new double[1+rowsb];
double z;
double *x = new double[rowsobj];
double *p = new double[rowsf];

lp = glp_create_prob();
glp_set_prob_name(lp, "sample");
//s3: glp_set_obj_dir(lp, GLP_MAX);
glp_add_rows(lp, rowsf);
//glp_set_row_name(lp, 1, "p");
//glp_set_row_bnds(lp, 1, GLP_FX, 100.0, 100.0);
//glp_set_row_name(lp, 2, "q");
//glp_set_row_bnds(lp, 2, GLP_FX, 600.0, 600.0);
//glp_set_row_name(lp, 3, "r");
//glp_set_row_bnds(lp, 3, GLP_FX, 300.0, 300.0);
for (int i = 0; i<rowsf; i++){ // these are the f's
//glp_set_row_name(lp, i+1, "aaaa");
glp_set_row_bnds(lp, i+1, GLP_FX, farray[i], farray[i]); 
}

//glp_add_cols(lp, 3);
glp_add_cols(lp, rowsobj);
//glp_set_col_name(lp, 1, "x1");
//glp_set_col_bnds(lp, 1, GLP_LO, 0.0, 0.0);
//glp_set_obj_coef(lp, 1, 10.0);
//glp_set_col_name(lp, 2, "x2");
//glp_set_col_bnds(lp, 2, GLP_LO, 0.0, 0.0);
//glp_set_obj_coef(lp, 2, 6.0);
//glp_set_col_name(lp, 3, "x3");
//glp_set_col_bnds(lp, 3, GLP_LO, 0.0, 0.0);
//glp_set_obj_coef(lp, 3, 4.0);
for (int i = 0; i<rowsobj; i++){
//glp_set_col_name(lp, i+1, "bbbb");
glp_set_col_bnds(lp, i+1, GLP_LO, 0.0, 0.0);
glp_set_obj_coef(lp, i+1, objarray[i]);
}
//ia[1] = 1, ja[1] = 1, ar[1] = 1.0; /* a[1,1] = 1 */
//ia[2] = 1, ja[2] = 2, ar[2] = 1.0; /* a[1,2] = 1 */
//ia[3] = 1, ja[3] = 3, ar[3] = 1.0; /* a[1,3] = 1 */
//ia[4] = 2, ja[4] = 1, ar[4] = 10.0; /* a[2,1] = 10 */
//ia[5] = 3, ja[5] = 1, ar[5] = 2.0; /* a[3,1] = 2 */
//ia[6] = 2, ja[6] = 2, ar[6] = 4.0; /* a[2,2] = 4 */
//ia[7] = 3, ja[7] = 2, ar[7] = 2.0; /* a[3,2] = 2 */
//ia[8] = 2, ja[8] = 3, ar[8] = 5.0; /* a[2,3] = 5 */
//ia[9] = 3, ja[9] = 3, ar[9] = 6.0; /* a[3,3] = 6 */
for (int i = 0; i<rowsb; i++){
	ia[i+1] = (int)Barray[i][0];
	ja[i+1] = (int)Barray[i][1];
	ar[i+1] = (int)Barray[i][2];
}
//glp_load_matrix(lp, 9, ia, ja, ar);
 glp_load_matrix(lp, rowsobj*rowsf, ia, ja, ar);
glp_simplex(lp, NULL);
z = glp_get_obj_val(lp);
//x1 = glp_get_col_prim(lp, 1);
//x2 = glp_get_col_prim(lp, 2);
//x3 = glp_get_col_prim(lp, 3);
for (int i = 0; i<rowsobj; i++){
x[i] = glp_get_col_prim(lp, i+1);
}
printf("\nz = %g; x1 = %g; x2 = %g; x3 = %g\n",
z);//, x1, x2, x3);
for (int i = 0; i<rowsobj; i++){
printf("x = ", x[i]);
}
glp_delete_prob(lp);
	 int cat;
	 cin >> cat;
return 0;
}
/* eof */

I am using the gnu glpk library to calculate a linear program for my matrices.

Does anyone know why I get the error message exit code 3 which apparently means "The system cannot find the path specified"?

Thanks in advance!