I have to write a program that is set up like a multiplication table. When I run the program it is to look like this:
1 0 1 2 3 4 5 6 7 8 9
2
3
4
There is supposed to be four rows, hence 1234. Then, starting with 0, it is supposed to multiply the row * column. So I know my calculation part of the program is product = row * column. The code I have so far only does the 9's. Here is a copy of my code:
//declare variables
int product = 0;
int row = 0;
int column = 0;
for (int column = 1; column <= 4; column += 1)
{
for (int row = 1; row <= 9; row += 1)
product = row * column;
cout << product;
//end for
cout << endl;
} //end for
system ("pause");
return 0;
Can someone please steer me in the right direction on what's wrong? Again, not completely comfortable with the tech talk, so kinda keep it dumbed down some. Of and we are supposed to use two for statements not a while. Thanks!
You have shot yourself in the foot by not laying out your code in a way that makes it easy to see your own mistakes. See your //end for lines? Only one of them is actually closing a for. You missed out the braces around the second forloop's code.
Compare this code with your code. I've added a { and a } and layed it out in such a way that you can see the loops easily.
I just run the program and the only problem I have now is the top row (1 2 3 4 5 6 7 8 9) is missing the 0.
This is what is supposed to look like:
1 0 1 2 3 4 5 6 7 8 9
2
3
4
This is what I have: ( there should be a 0 1 on the top row between the 1 2)
1 2 3 4 5 6 7 8 9
2
3
4
When I change the int row = 0, it gives me a bunch of 0's.
...then change column to 0. Then the entire first column will, of course, be zero.
[edit]
By the way, which compiler/IDE are you using? I'm guessing Dev-C++, because your code shouldn't really compile on a proper compiler. The variables 'row' and 'column' are declared twice: once at the start and again in their loops. This should show errors at compile time.
When I change it to a 0, I get nothin but 0's across the top. (below is what my out come is)
0000000000 <----------------------------------------those are in the wrong place on mine.
1 2 3 4 5 6 7 8 9 -------------------------------------In the code above I changed the 1 to a 0 in the
2 2 4 6 8 10 12 14 16 18---------------------------and got the code to the left.
3 6 9 12 15 18 21 24 27
4 8 12 16 20 24 28 32 36
I need those 0's like this (below is what my outcome should be)
1 0 1 2 3 4 5 6 7 8 9
2 0 2 4 6 8 10 12 14 16 18
3 0 6 9 12 15 18 21 24 27
4 0 8 12 16 20 24 28 32 36