So I have to create a multiplication table but it has to be the size of a number I enter from 5 to 31. I think I understand creating a multiplication table without an input, but how do I do it when it has to be a specified size?

cout << "Enter a number between 5 and 31: ";
cin >> num;

do {
cout << "Enter a number between 5 and 31: ";
cin >> num;
} while (num<MULT_MIN || num > MULT_MAX);

while (num <MULT_MIN || num > MULT_MAX)

not much but I'm stuck

>>I think I understand creating a multiplication table without an input
Not much different. Post how you would do it without input and we'll show you what you need to change to make it work with input.

I think of dynamic memory whenever I have to wait for user input to determine the size of an array.

A table is usually a 2 dimensional array.

A multiplication table is probably a 2 dimensional array of size x by x where x is both the number of rows and the number of columns in the table.

To create a 2 dimensional array of size x by x using dynamic memory you need to do something like this:

int x;
get user input for x
int rows = x;
int cols = x;

int **table;
table = new int*[rows];
for(int i = 0; i < rows; ++i)
{
    table[i] = new int[cols];
}

This is how I would create a multiplication table without the set parameters.

cout << "Enter a number for the deminsion of the table: ";
    cin >> num;
    cout << endl;

    for (i = 1; i <= num; i++) {
        for (j = 1; j <= num; j++) {
            cout << i*j << "\t";
        }
        cout << endl;
    }

That will display information in a tabular format, but not create a table to store the information in for future use. If that's what you want to do, go for it.

This article has been dead for over six months. Start a new discussion instead.