I'm using PASCAL for a course i'm doing and i'm having trouble with an assignment, in my program i'm using 2 arrays that uses a variable from a user's input but when i go to run the program it comes up with, Error: Can't evaluate constant expression. The code for the array is:
x : integer;
s : array[1..x] of real;
n : array[1..x] of string;
x is a variable, that won't work indeed. The range of a so called static array must be a constant expression, i.e. it must be known at compile time.
So what you want won't work, as is.
In FreePascal, you can use dynamic arrays, though. Their lengths can be set and changed at runtime.
var x: Integer; s: array of Real; n: array of string; // why not just string?
x := someUserInput(); // pseudo code! SetLength(s, x); SetLength(n, x);
for q := Low(s) to High(s) do // access s[q];
High() are not the topic, but just know they can also be used for static arrays, and that they return the actual array bounds -- I always use High and Low for this)