Headers for colums and rows

This is the program I've written and I need to add columns and rows for the table. Like most people here I'm just starting so I'm in the dark as to what I'm suppose to do.

#include<iostream>
#include<iomanip>

using namespace std;

int main()

{
double m,n;

cout<<"Please enter interger for m "<<endl;
cin>>m;
cout<<"Please enter interger for n"<<endl;
cin>>n;

for (int r=1; r<=m; r++)
{

for (int c=1; c<=n; c++)
{
cout<<setw(3)<<c*r;
}
cout<<endl;
}


system("pause");

return 0;

}

Any help as to how to add those headers would be appreciated.
I'm not sure what you mean. Do you mean "add column titles"? If so, please avoid the word "header" for that, because that has a completely different meaning in C++.

If so you can simply add another for loop before your column loop:

1
2
3
for(int ch = 1; ch <= n; ++ch) {
  cout << setw(3) << "Header" << ch;
}


This will add the word "Header1" at the top of first column, "header2" for the second and so on.
You'll have to excuse my ignorance. I'm very new to this and I think I used the wrong term. Basically its suppose to spit out the same amount of numbers for both columns and rows. So you see numbers 1 thru whatever and then the table. It looks like I can use the coding you wrote and just use the same code as the for(int...) to populate it.
Topic archived. No new replies allowed.