"nested" for loops for brute force calculating

Thread Starter

happykirwan

Joined Oct 4, 2011
2
Hello.

I am a first year student in Electrical Engineering and I was having a little bit of trouble with a program I have to write. Without going into too much detail, I am making a program that will take a class A amplifier circuit and calculate gain, input impedance, etc with ALL values of resistors, and spit out answers according to a tolerance. I am having issues with the for loops.

What I have tried is this: I made multiple for loops, each which reference an array of resistor values. When all the calculations are done, it changes one of the resistors, and does all the calculations again. At least, this is how it should work.

Here's what I have so far:
Rich (BB code):
//FOR THE FOR LOOPS
	int count1=0;
	int count2=0;
	int count3=0;
	int count4=0;
	int count5=0;

for (R1 = E24_Resistor[count1]; count1 < 170; count1++)
	{
		R1 = E24_Resistor[count1];

		for (R2 = E24_Resistor[count2]; count2 < 170; count2++)
		{
			R2 = E24_Resistor[count2];

			for (Rc = E24_Resistor[count3]; count3 < 170; count3++)
			{
				Rc = E24_Resistor[count3];

				for (Re = E24_Resistor[count4]; count4 < 170; count4++)
				{
					Re = E24_Resistor[count4];

					for (Vs = VOLTAGE[count5]; count5 < 41; count5++)
					{
						Vs = VOLTAGE[count5];
//MY CALCULATIONS AND WHAT NOT GO HERE

Then under this mess I have all my calculations. The problem I am having is that the voltage array is working fine (i've been stepping through line by line), but as soon as the value for count5 = 41, the program just stops.. without dropping into the resistor for loops. I'm sure I am missing something simple, but I simply cannot figure out what it is!

Any help would be GREATLY appreciated. And if the whole source file or the arrays or anything is needed, I would be more than happy to post them.
 

MrChips

Joined Oct 2, 2009
30,712
You have to initialize the counters in the for loop, for example:

Rich (BB code):
for (count5 = 0; count5 < 41; count5++)
{
  Vs = VOLTAGE[count5];
}
 
Top