Need help making a table

I need to make a table made of 4 rows and 11 columns. The first column has the numbers 1, 2, 3, and 4, the rest of the columns contain the results of multiplying the number in the first column by the numbers 0 through nine. It should look something like this:

1 0 1 2 3 4 5 6 7 8 9
2 0 2 4 6 8 10 12 14 16 18
3 0 3 6 9 12 15 18 21 24 27
4 0 4 8 12 16 20 24 28 32 36


Alignment isn't important, but I need to make it using two for statements.

Any ideas?
Have the first for loop to be x=1;x<=4;x++ and the other loop, say, int y, be 0 to 9.
cout the x and a space. Then in the y loop, cout x*y and a space.
After the y loop, cout a newline with endl or '\n'.
Could you put that in C++ code for me?
Yeah, I could, but I would rather see what you write first. I gave you everything you need to write it. I wrote it already, and it was only 5 lines long, not counting the braces '{' and '}'. I'll help you through the programming, not over it.
Okay, but could you a least clarify what the variables are, if any?
The variables are anything you want to name them. You can use the int x and int y, if you want, or you could call them int column and int row. Names are just place-holders in memory for the values.
I'm assuming the second loop is a nested loop, correct?
Yes it is.
Heres an outline of what you'll want to do:

1
2
3
4
5
6
//for(Integer representing rows;how many rows?;what do you add to reach the next row?){
    //this is a NESTED for(integer representing columns;how many columns?;how do you reach the next column?){
       // this code here representing the code for the 1st row, it will run through the desired columns
       //and end, starting up the first for loop again which moves down one row
    //}
//} 


understand?
Last edited on
And after the 2 for statements how should I finish it up so it will display the table? Should it be something like "x += 1" or some other code?
Last edited on
After the two for loops, the table IS finished.
So I just put in

system("pause");
return 0;

and I'm done?
if you want to print out the table and say, you made the two for loop ints 'Rows' and 'Cols'
then you would write std::cout << Array[Rows][Cols] in the middle, and std::cout << std::endl; after the nested for loop(but still inside the main loop). Is that what you were asking?
Last edited on
Thanks you guys, you really saved my bacon.
A lot of programmers dislike using system calls, as they may not work properly on ALL systems, but for your first or second program, I think it's okay to do. After that, try finding better solutions on pausing the program.
Have you almost finished writing the program yet? Would love to see it.
@toradow777, you are definitely in the same boat that I was in a few hours ago. Unfortunately I had to give up on the assignment. Intermediate22.cpp Yeah, I've been struggling since chapters 3 & 4 and barely making it by. Now I'm completely lost. I guess I will be taking this course all over again next semester.
ProWorks, why dont you post threads asking for help here? The people here would love to help a struggling student with his homework, provided he put the effort in.
I would have loved to post up threads about my concerns for this course. But I only stumbled across this site hours ago and registered. But I believe with only a few weeks left in this semester, I'm afraid it is a little too late. I've been struggling in this course since chapt. 3 and 4, but managed to wing it and make it by. Now I'm to the point where I'm totally lost.
Topic archived. No new replies allowed.