First of all, I don'y know POINTERS and OTHER HIGH LEVEL PROGRAMMING cuz I study C++ in my school.
Secondly, I use Borland C++ Version 3.0
I am trying to create a code that inputs an array size, then inputs the array then print it s corresponding pattern. Example
If we input size 3, then we will input array like this:
1
2
3
then it will print pattern like this:
123
120
100
The Only problem is that my code is giving error that constant expression required in the function that is outside of main(). Please tell the direct solution, I have to submit my project tomorrow and its already night here in India. I have done this code on my own and I'm not asking to rebuild the whole code, just tell me how to make it constant by a method which is not so advanced. Please help.
The Only problem is that my code is giving error that constant expression required in the function that is outside of main().
Well you're probably going to need to learn the following:
First of all, I don'y know POINTERS and OTHER HIGH LEVEL PROGRAMMING
In C++ array sizes must be compile time constants, for example:
1 2 3 4 5 6 7
int intArray[10]; // Okay using a constant (10).
constint ArraySize = 100;
int anotherIntArray[ArraySize]; // Okay using a const qualified value.
int someValue = 11;
int aBadSize[someValue]; // Error: Not a compile time constant.
The other option is to use dynamic memory new/delete, which means pointers.
And you really need to find a newer compiler, that compiler was probably obsolete before you were born. Download a modern IDE/compiler, like Visual Studio express, or Code::Blocks with the most recent version of gcc.
The Only problem is that my code is giving error that constant expression required in the function that is outside of main(). Please tell the direct solution
The direct solution is to use a constant expression, as your compiler has already told you.
I have done this code on my own and I'm not asking to rebuild the whole code, just tell me how to make it constant by a method which is not so advanced.
What you may do is just make the array(s) large enough that it will serve for any value entered by the user (and perhaps, then, informing the user when the number entered is not appropriate would be a good addition to the code.)
If you delete line 37 and line 43, the program works.
Your compiler has an extension which allows the use of variable length arrays in C++. Unfortunately, using the extension means the compiler accepts non-conforming programs like this one without complaint. The use of the -pedantic option is recommended for compiling C++ with g++ if you wish to write standard compliant code.