nested loop not testing all the way through

Okay i've finally figured out this whole nested loop thing , well kind of, for this program I needed to create a nested loop for a lumber yard the base sizes for the wood are 2,4,6,8,10 and the height size is 2,4,6,8,10,12. The formulas and stuff are kind of irrelevent for my question because I have all of that working. My question is WHY in the world is my outer loop stopping at 8 when it is supposed to test until it is <= 12. Here's the code

#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
// Heading for the chart

cout << "Lumber Size" <<" "<< "Cross-sectional area" <<
" "<< "Moment of inertia" << " "<< setw(10)<<
"S M \n";
// nested for loop for everything in the chart

for(int i=2; i<=12; i*=2)
{
for(int j=2; j<=10; j*=2)
cout<< j <<"X" << i << setw(20) << j*i <<
setw(25)<< (j * (i*i*i))/12<< setw(16)<<
(j*(i*i))/6 << endl;

}

return 0;

}


Here's what the program is displaying:

Lumber Size Cross-sectional area Moment of inertia S M
2X2 4 1 1
4X2 8 2 2
8X2 16 5 5
2X4 8 10 5
4X4 16 21 10
8X4 32 42 21
2X8 16 85 21
4X8 32 170 42
8X8 64 341 85

RUN SUCCESSFUL (total time: 114ms)

It's kind of off after copying but i swear its all lined up in netbeans haha


Last edited on
Bc *= 2 means
2 * 2 = 4
4 * 2 = 8
8 * 2 = 16

That breaks your loop.

Your third statement in your fors should be i += 2 and j += 2 respectively.
Something so small, yet so significant.. Works perfectly now thanks
Topic archived. No new replies allowed.