Sorry in advance for such a simple question I'm very new to c++ and just started last week. I'm trying to make a table that makes 3 rows and 11 columns and can't figure out why my algorithm is off so much. the output is supposed to read
#include <iostream>
usingnamespace std;
int main()
{
for (int x = 1; x < 4; x++ )
{
cout << x << " ";
for (int y = 0; y < 10; y++)
{
cout << y << " ";
y = x * y;
} //end for
cout << endl;
} //end for
cout << endl;
return 0;
} //end of main function
In the inner for loop you are changing y to equal x*y, which means that loop will not go with y from 0 to 9 as expected. Instead, you should just cout "x * y" directly instead of screwing up your loop variable.
Z : Thanks you! I knew it was something stupid.. I just cout like you stated and it worked flawlessly.
m4ster : thanks for writing that up.. it actually made me understand it a little more but I'm gonna keep playing around with it just to see different results.
#include <iostream>
usingnamespace std;
int main()
{
for (int x = 1; x < 4; x++ )
{
cout << x << " ";
for (int y = 0; y < 10; y++)
{
cout << x* y << " ";
//y = x * y;
} //end for
cout << endl;
} //end for
cout << endl;
system ("pause");
return 0;
} //end of main function