Hello, I had to creat the following code that displays a table depending on the number te user entered.

int main()
{
int n = 0;
const int base = 4;
std::cout << "Enter max: ";
std::cin >> n;
std::cout << " ";
for(int i = 1; i<= n; ++i)
std::cout << std::setw(base) <<i;

std::cout << "\n " << std::string(n * base, '-') << "\n";
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
{
if(j == 1)
std::cout <<std::setw(2) << i << '|';

std::cout << std::setw(base) << i * j;
}
std::cout<<"\n";
}

It works so far. I also need to display a message when the user enters a number less than zero or a number above my
multidimensional array.

if( n < 0 )
cout<<" hey dummy, can't be negative, trry again";
else if( n > maxN )
cout<< " hey stupid, don't you know nothing, try again;

How to I define " number above my multidimensional array" ? n > what ? Gotta define maxN somehow, but I don't know how...

well a multidimensional array has a max that is equal to the max of each dimension multiplied together. so if your array is array[10][5][20] then you would do 10*5*20 to get the max which would be 10000. this works no matter how many dimensions you have. so in your program you would set maxN to the max of each dimension in your array times each other.

well a multidimensional array has a max that is equal to the max of each dimension multiplied together. so if your array is array[10][5][20] then you would do 10*5*20 to get the max which would be 10000. this works no matter how many dimensions you have. so in your program you would set maxN to the max of each dimension in your array times each other.

Well, I don't understand. There's no [10],[5] etc since the user enters some value. What would it be in this case?

I see no arrays in your code. I think you're going to have to re-explain what you're trying to do. I for one don't understand what your goal is or what your question is, particularly this phrase:

a number above my multidimensional array

What does this mean? How do you compare an integer to an array?

Well, that's what we were supposed to do:

The task involves writing a C++ program that produces a multiplication table in two dimensional array. The first row consists of the multiplicands while the first column consists of the multipliers. For instance, for n=6, the multiplication table becomes:

|
| 1 2 3 4 5 6
--|--------------------------------
1 | 1 2 3 4 5 6
2 | 2 4 6 8 10 12
3 | 3 6 9 12 15 18
4 | 4 8 12 16 20 24
5 | 5 10 15 20 25 30
6 | 6 12 18 24 30 36

And that's what I did.

In addition to that:

If the user value is less than zero or above your multidimensional array, either prompt the user for proper value or use the default value 10.

That's what I am trying to do now.

Well, that's what we were supposed to do:

And that's what I did.

In addition to that:


That's what I am trying to do now.

I would have used different wording, but if that's the wording you were provided, then that's the wording you were provided. You may need to provide the whole spec, because it's unclear what the "user value" represents. You ask the user one question: what the max is. Is that the "user value"? You store it in n. So comparing n to the max is pointless since you've defined n to be the max. So something else must be going on. Is there no other user input?

No, as you can see there's no other input. That was the entire code. I still have no idea how to do this.
I guess I'll just limit it to 32x32.
Thanks everybody!

from what i can gander i believe that you need to have 1 two dimensional array. judging by the second quote the array should proboly have a size of 10*10 and you can either use 10 for the max or ask the user to input a number less than 10. the first dimension of the array will be 1 through the number entered by user. so if the user enters 6 the first dimension will have 1,2,3,4,5,6. the second dimension will hold the result of multiplying the value of the first dimension by all the values in the first dimension. so in this example will call the array numbers and it will be defined as int numbers[10][10]; . then you would ask the use for the number they would like the table to go up to. if it is less than zero or greater than ten then you need to issue an error and ask for a new number or use a default of 10. if the user enters 6 then you need and algorithm that will make the first dimension be 1-6 and the second dimension will hold the result of multiplying the first dimension by 1-6. maybe this will make things clearer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.