Oct 15, 2012 at 6:05pm UTC
Here's a fragment of what I'm trying to launch:
for (int i=0; i++; i<=3)
{
for (int j=0; j++; j<=3)
cout << (m_main[i][j]).a+(m_main[i][j]).b+(m_main[i][j]).c << "";
cout << "\n";
}
m_main is a matrix whose elements are arranged 3-element sets. The loop above is supposed to display part of its elements presented as sums of the three components.
Why doesn't this approach work?
It displays nothing instead of the i*j-grid, yet when the procedure
cout << (m_main[i][j]).a+(m_main[i][j]).b+(m_main[i][j]).c
is used alone with substituted i and j, it works fine.
The compiler doesn't find any errors.
Thanks for your help!
Last edited on Oct 15, 2012 at 6:08pm UTC
Oct 15, 2012 at 6:10pm UTC
i would put brackets around the addition such that
cout << (... + ... + ...) << endl;
Oct 15, 2012 at 6:13pm UTC
No, that didn't help. :/
Also, endl is redundant here because it would break the line.
Oct 15, 2012 at 6:26pm UTC
@thestraycat27
You could try, cout << m_main[i][j].a << m_main[i][j].b << m_main[i][j].c << endl;
, if you haven't, already.
And use this, if you need spaces between each of the outputs.
cout << m_main[i][j].a << " " << m_main[i][j].b << " " << m_main[i][j].c << " " << endl;
Last edited on Oct 15, 2012 at 6:40pm UTC
Oct 15, 2012 at 6:40pm UTC
It's
for (int i=0; i<=3; i++)
not
for (int i=0; i++; i<=3)
Oct 15, 2012 at 6:45pm UTC
What type are a, b and c, and just what do you think those parentheses are doing other than making your code less readable?
What do you mean it displays nothing?
Oct 15, 2012 at 6:46pm UTC
Oh no, how the ... could I?!..
Well, thanks, Caligulaminus. It must be okay now. Sorry for my stupidity.
Last edited on Oct 15, 2012 at 6:48pm UTC