Oct 29, 2017 at 11:03pm UTC
Anyone know how to add the top layer of my multiplication table?Plus, if the users enters an integer above 10 i get some weird junk value.
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
#include<iostream>
#include <iomanip>
using namespace std;
int main ()
{
int size;
int row;
int col;
int nums[row][col];
cout << "Enter table size" << endl;
cin >> size;
cout << endl;
for (int row = 1; row <= size; row++)
{
cout << right << setw(2) << row << setw(2) << "|" ;
for (int col = 1; col <= size; col++)
{
nums[row][col] = row*col;
cout << setw(4) << nums[row][col];
}
cout << endl << endl;
}
return 0;
}
This is what it prints when user enter a digit below 10
(This print the numbers out of alignment but in my code they are aligned)
Enter table size
5
1 | 1 2 3 4 5
2 | 2 4 6 8 10
3 | 3 6 9 12 15
4 | 4 8 12 16 20
5 | 5 10 15 20 25
Any digit above ten
Enter table size
11
1 | 1 2 3 4 5 6 7 8 9 10-1081305424
Segmentation fault
plus i need the top part of my multiplication table. but am not sure how
Last edited on Oct 29, 2017 at 11:20pm UTC
Oct 29, 2017 at 11:25pm UTC
@ne555
The top part of the table just like the left side.
1|
2|
3|
etc.
i need a top part like this(but aligned).
1 2 3 4 5 6
----------------
1 |
2 |
3 |
4 |
5 |
6 |
for the 'nums' part, i am not sure. I just thought it was a variable name you need to create for the array. Im new to this :/
Last edited on Oct 29, 2017 at 11:33pm UTC