Hey all, I'm new to C++ and struggling to write a program. I am used to writing in VBA and Mathlab but because I need to run a long run simulation have to rewrite my program in C++. What a am trying to do is if I have a list of values say:

position_axle1
position_axle2
position_axle3
position_axle4
position_axle5
position_axle6
position_axle7
position_axle8

and I am genarating arrays like:

truck_data1[22]
truck_data2[22]
truck_data3[22]

The part I am having trouble writing is if I want a loop that will pick the next "position_axle" in each loop how do i write it.Here is my attempt:

for (int i = 1; i = 100; i = i + 1)
{

 int p = 1, q = 3;
 double position_axle(i), AxleInfluenceLineXAxleWeight(i);


	if(position_axle(i) > bridge_length)
		AxleInfluenceLineXAxleWeight(i) = 0;
	else if (position_axle(i) < 0)
		AxleInfluenceLineXAxleWeight(i) = 0;

		else if	(position_axle(i) < (bridge_length/2))
			AxleInfluenceLineXAxleWeight(i) = (position_axle(i)/2) * truck_data(p)[q];
			else
			AxleInfluenceLineXAxleWeight(i) = ((bridge_length - position_axle(i))/2) * truck_data(p)[q];

q = q + 1;

if(q > 12)
	q = 3;


if(i >=10)
	p = 2;
else if(i >= 20)
	p = 3;
else if(i >= 30)
	p = 4;
else if(i >= 40)
	p = 5;
else if(i >= 50)
	p = 6;
else if(i >= 60)
	p = 7;
else if(i >= 70)
	p = 8;
else if(i >= 80)
	p = 9;
else if(i >= 90)
	p = 10;



	if (load_effect1 > max_load_effect1)
		max_load_effect1_1 = load_effect1;
	else
		max_load_effect1_1 = max_load_effect1_1;

	t = t + 0.02;
	}
return (max_load_effect1_1);

I don't understand the relationship between truck_data and position_axle

Maybe give a sample input/output?

Sorry I got call i middle of writing thread and I got cut off before I could touch up my message:

// Calculate Load Effect 1

double cal_load_effect1(double truck_data1[22]... to double truck_data10[22]... , double bridge_length)
{

t = 0;

truck_crossing = ((truck_data1[2] + bridge_length) / truck_data1[1]);		// time it takes for truck to cross bridge (sec)


while (t < truck_crossing)
{


	position_axle1 = truck_data1[1] * t;
	position_axle2 = position_axle1 - truck_data1[13];
	position_axle3 = position_axle2 - truck_data1[14];
	position_axle4 = position_axle3 - truck_data1[15];
	position_axle5 = position_axle4 - truck_data1[16];
................ to  position_axle100

for (i = 1; i = 100; i = i + 1)
{

 int p = 1, q = 3;


	if(position_axle[i] > bridge_length)
		AxleInfluenceLineXAxleWeight[i] = 0;
	else if (position_axle[i] < 0)
		AxleInfluenceLineXAxleWeight[i] = 0;

		else if	(position_axle[i] < (bridge_length/2))
			AxleInfluenceLineXAxleWeight[i] = (position_axle[i]/2) * truck_data[p][q];
			else
			AxleInfluenceLineXAxleWeight[i] = ((bridge_length - position_axle[i])/2) * truck_data[p][q];

q = q + 1;

if(q > 12)
	q = 3;


if(i >=10)
	p = 2;
else if(i >= 20)
	p = 3;
else if(i >= 30)
	p = 4;
else if(i >= 40)
	p = 5;
else if(i >= 50)
	p = 6;
else if(i >= 60)
	p = 7;
else if(i >= 70)
	p = 8;
else if(i >= 80)
	p = 9;
else if(i >= 90)
	p = 10;
load_effect1 = sum(AxleInfluenceLineXAxleWeight(i));
}

	if (load_effect1 > max_load_effect1)
		max_load_effect1_1 = load_effect1;
	else
		max_load_effect1_1 = max_load_effect1_1;

	t = t + 0.02;
	}



return (max_load_effect1_1); 

}

The trouble I am having is that referencing an array in the loop as "truck_data[p][q]" seems to be causing some issues. Thanks in advance for any help.

Colm.

Hey David, thanks for reply. The truck_data is an array that holds the data about the truck such as axle spacing and axle weight. I am basiciall writing a program that is marching the trucks over a bridge in steps of 0.02 seconds and recording the largest load effects. The position_axle(i) is used to find the position of each of the trucks axles at a given time and hence calculate the load effects.
Thanks for reading the post.
Colm

This question has already been answered. Start a new discussion instead.