<< setw help needed, table not printing right

I have a program that prints a table of exponents. It works completely except the columns of numbers aren't lined up right. For example, with input 5 and 4 the program is supposed to print:
1
2
3
4
5
 1       1       1       1
 2       4       8      16
 3       9      27      81
 4      16      64     256
 5      25     125     625

but instead it prints: (screencap instead of output because I can't get the thing to paste accurately)
http://cboard.cprogramming.com/attachments/cplusplus-programming/13842d1420092680-setw-help-needed-table-not-printing-right-programming_help.png
As you can see, the lining up is wrong. My code is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <iomanip>
// this one always prints 1 before the *CORRECT RESULT* then leaves off the final result at the other end 
using namespace std;
  
int pow(int b, int e) {
    if (e == 0) {
        return 1;
    }
    else {
        return b * pow(b,e-1);
    }
}
  
// if putting the table code in pow doesn't work, insert table function here
int table(int var, int yar) {
    for (int r = 0; r < var; r++) {
        cout << left;
        for (int c = 1; c <= yar; c++) {
            cout << "  ";
            cout /*<< left*/ << setw(6) << pow(r + 1, c);
        }
        cout << endl;
    }
    return 1;
}
  
int main() {
    int rows;
    int columns;
    cout << "This program prints a table of exponential powers." << endl;
    cout << "Enter the number of rows to print: ";
    cin >> rows;
    cout << "Enter the number of powers to print: ";
    cin >> columns;
    table(rows, columns);
    cout << endl;
    pow(rows, columns);
}

I went searching online for advice on this which is what directed me to put in the << left, which I didn't know existed. Changing << left to right FIXES the problem, only the output is shifted several spaces to the right.
Can someone please help? This is for an assignment which has a very picky online grader so it has to be exactly as it expects.
1
2
3
4
5
6
7
8
9
10
int table(int var, int yar) {

    for (int r = 0; r < var; r++) {
        for (int c = 1; c <= yar; c++) {
                cout << setfill (' ')<< setw(6)<< pow(r + 1, c);
        }
        cout << endl;
    }
    return 1;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
  
void table(int var, int yar) {

    for(int r = 0; r < var; r++) {
    	cout << r+1;
        for(int c = 2; c <= yar; c++) {
            cout << setfill (' ')<< setw(6)<< pow(r + 1, c);
        }
        cout << endl;
    }    
return;
}
  
int main() {
	cout << "This program prints a table of exponential powers.\n";
    int rows = 5;
    int columns =4;
    table(rows, columns);
    cout << endl;
    pow(rows, columns);
    
return 0;    
}
I tried anup30's suggestion and now it almost works only there is no 2 spaces before all the columns. Please help! What I have now:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <iomanip>
// this one always prints 1 before the *CORRECT RESULT* then leaves off the final result at the other end 
using namespace std;
  
int pow(int b, int e) {
    if (e == 0) {
        return 1;
    }
    else {
        return b * pow(b,e-1);
    }
}
  
// if putting the table code in pow doesn't work, insert table function here
void table(int var, int yar) {
    for (int r = 0; r < var; r++) {
        cout << r+1;
        for (int c = 1; c <= yar; c++) {
           /* cout << "  "; */
            cout << setw(2);
            cout << setfill(' ') << setw(7) << pow(r + 1, c);
        }
        cout << endl;
    }
    return;
}
  
int main() {
    int rows;
    int columns;
    cout << "This program prints a table of exponential powers." << endl;
    cout << "Enter the number of rows to print: ";
    cin >> rows;
    cout << "Enter the number of powers to print: ";
    cin >> columns;
    table(rows, columns);
    cout << endl;
    pow(rows, columns);
}
setw(8)
I have it working but there are 8 spaces before everything instead of 2.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <iomanip>
// this one always prints 1 before the *CORRECT RESULT* then leaves off the final result at the other end 
using namespace std;
  
int pow(int b, int e) {
    if (e == 0) {
        return 1;
    }
    else {
        return b * pow(b,e-1);
    }
}
  
// if putting the table code in pow doesn't work, insert table function here
void table(int var, int yar) {
    for (int r = 0; r < var; r++) {
       // cout << r+1;
        for (int c = 1; c <= yar; c++) {
           /* cout << "  "; */
           // cout << setw(2);
            cout << setfill(' ') << setw(8) << pow(r + 1, c);
        }
        cout << endl;
    }
    return;
}
  
int main() {
    int rows;
    int columns;
    cout << "This program prints a table of exponential powers." << endl;
    cout << "Enter the number of rows to print: ";
    cin >> rows;
    cout << "Enter the number of powers to print: ";
    cin >> columns;
    table(rows, columns);
    cout << endl;
    pow(rows, columns);
}
This program prints a table of exponential powers.
Enter the number of rows to print: 5
Enter the number of powers to print: 10
       1       1       1       1       1       1       1       1       1       1
       2       4       8      16      32      64     128     256     512    1024
       3       9      27      81     243     729    2187    6561   19683   59049
       4      16      64     256    1024    4096   16384   65536  262144 1048576
       5      25     125     625    3125   15625   78125  390625 1953125 9765625


Looks fine. What's exactly the problem?
Topic archived. No new replies allowed.