Okay, I got a school assignment and got a problem here.
It says that:
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:5: parse error before `:='

I know there's wrong with the array, but I want the user to write how many letters his/her name contains so that the array can take each letter out later to make it spelled backwards or something (if it's possible)

I'm a noob on this and I really want to learn, but this error is one I've never gotten before.

Code (HTML'ed so it's easier to read):

PROGRAM inlupp2;
{small bolded letters are "mini" local programs and big bold letters are the "Global" program}
{Here's the resources for my program}

USES
{Get's me some commands to give colours and clear screen etc.}
crt;
VAR
{Variables in my program}
i,firstnamelettercount:integer;
{An array in my program}
firstnameletters:array[1..firstnamelettercount] of integer;

{Here the main program starts}
BEGIN
Writeln('Welcome to Patrik "Loyen" Freijs latest program.');
Delay(2000);
writeln;
writeln('We will start with some questions so we know WHO you are.');
Delay(3000);
writeln;
write('We will start off with');
Delay(1000);
write(' how many letters does your first name contain? ');
{Here we makes the user write in an answer for "firstnameletters"}
readln(firstnamelettercount);
write('Your name includes ',firstnamelettercount,'. Now tell us your name.');

readln;
END.

Please help this swedish noob!

*updated code*

When you post code, stick it in code blocks:

[[I][/I]code=Pascal[I][/I]]
program Hello;
begin
writeln( 'Hello, world!' )
end.
[[I][/I]/code[I][/I]]

becomes:

program Hello;
begin
writeln( 'Hello, world!' )
end.

This is the easiest to read and use. Click the little Toggle Plain Text link at the top to get something you can copy and paste.

You have not posted the code you tried to compile. There is no := in there at all.

Some suggestions:
- Don't use delay. It is obnoxious and unnecessary.
- Your array should be: firstnameletters: string; Strings are capable of reporting their length:

var firstname: string;
begin
  write( 'Please enter your first name> ' );
  readln( firstname );
  writeln( 'Your name has ', length( firstname ), ' letters.' )
end.

Please post all the code you are having trouble with in code blocks.

Hope this helps.

PROGRAM inlupp2;
{small bolded letters are "mini" local programs and big bold letters are the "Global" program}
{Here's the resources for my program}

USES
{Get's me some commands to give colours and clear screen etc.}
    crt;
VAR
   {Variables in my program}
   i,firstnamelettercount:integer;
   {An array in my program}
   firstnameletters:array[1..firstnameletters] of string;
   firstnameletters:string;



{Here the main program starts}
BEGIN
Writeln('Welcome to Patrik "Loyen" Freijs latest program.');
Delay(2000);
writeln;
writeln('We will start with some questions so we know WHO you are.');
Delay(3000);
writeln;
write('We will start off with');
Delay(1000);
write(' how many letters does your first name contain? ');
{Here we makes the user write in an answer for "firstnameletters"}
readln(firstnamelettercount);
write('Your name includes ',length(firstnameletters),'. Now tell us your name.');

readln;
END.

Gives me:

D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:12: undeclared identifier `Firstnameletters' (first use in this routine)
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:12: (Each undeclared identifier is reported only once
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:12: for each routine it appears in.)
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:12: subrange bounds must be of ordinal type
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:12: ordinal type expected
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:12: warning: missing string capacity - assuming 255
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:13: warning: missing type in declaration of `Firstnameletters'
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:13: `Firstnameletters' used prior to declaration
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:13: warning: missing string capacity - assuming 255
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:18: redeclaration of `Firstnameletters'
D:\Skola\Programmering A\Inlämningsuppgifter\inlupp_2\Inlupp_2.pas:13: previous declaration of `Firstnameletters'

How do I add the firstnameletter:string; to the array?

Get rid of line 12. Please pay attention to the examples I've already given you. One of them answers your question (I think -about reading the letters of the first name into the string).

Pascal (as most every other language) requires constant bounds when you declare an array. For example: const MAX = 100; var a: array[ 1..MAX ] of char; Since MAX is a constant value, the compiler sees that variable definition as: var a: array[ 1..100 ] of char; You cannot use a variable in an array definition.

You are using an old Turbo Pascal, methinks? Or at least some Borland dialect? If you are you get the string data type, which, as I said, knows and reports its own length. Please see the example I already posted for you.

If you are using Delphi, you also get dynamic arrays, where you can say: var a: array of integer; You can set the length of the array: setLength( a, 100 ); As well as get the length as usual: writeln( 'The array is ', length( a ), ' integers long.' ); Hope this helps.

Good enough. Bloodshed DEV is an IDE. It actually compiles your programs using either FreePascal or GNU Pascal --both of which have a Borland mode. So you'll get dynamic arrays and everything! (Bonus points! Yay!)

Thanks for the help! it worked so well.. til' now I got a new problem.. xD sorry 'bout that.

It doesn't calculate out the right thing.. it gets.. like 463453 when it's just 1+1+1. :(

PROGRAM inlupp2;
{small bolded letters are "mini" local programs and big bold letters are the "Global" program}
{Here's the resources for my program}
USES
{Get's me some commands to give colours and clear screen etc.}
    crt;
VAR
   {Variables in my program}
   i,forloop1:integer;
   optionA,math1,math2:char;
   {An string in my program}
   firstname,lastname:string;
         {Procedure Calculator start}
         procedure calculatorprocedure(forloop1_1:integer);
         var {Procedure calculatorprocedure's variables}
            loop1,j,amount:integer;
            {array loop1numbers}
            loop1loopnumbers:array[1..forloop1_1] of integer;
         {Here starts the calculatorprocedure}
         begin
         {loop1 starts}
         for loop1:=1 to forloop1_1 do begin
         write('Write a number: ');
         readln(loop1loopnumbers[j]);
         {loop1 ends}
         end;
         writeln;
         amount:=amount+loop1loopnumbers[j];
         Writeln('The amount is ',amount);
         {Procedure Calculator end}
         end;


{Here does the main program start}
BEGIN
Writeln('Welcome to Patrik "Loyen" Freijs latest program.');
Delay(2000);
writeln;
writeln('We will start with some questions so we know WHO you are.');
Delay(3000);
writeln;
write('We will start off with');
Delay(1000);
write(' what is your firstname? ');
{Here we makes the user write in an answer for "firstname"}
readln(firstname);
Delay(500);
writeln;
write('Thank you. Now tell us your lastname. ');
{Here we makes the user write in an answer for "lastname"}
readln(lastname);
Delay(500);
writeln;
writeln('SAVED ID SUCCESFULLY');
Delay(500);
{ClearScreen commando}
ClrScr;
{Here we got the main menu of this program}
writeln('Welcome, ',firstname,' ',lastname,' to the test area.');
Delay(2000);
writeln;
writeln('We will show you the offers Patrik has made able for you to choose on.');
write('The categories are: ');
Delay(1000);
write('C: Calculator  ');
Delay(1000);
write('N: The New Name Test  ');
Delay(1000);
writeln('or  Q: The quitter');
Delay(600);
writeln;
write('What do you want to choose? ');
{Here is option A, the first option you get in this program}
readln(optionA);
                {Here does option A, that will say the calculator, start}
                if (optionA='C') or (optionA='c') then begin
                writeln;
                Write('You have chosen the calculator. Proceed by pressing ENTER');
                readln;
                {ClearScreen commando}
                ClrScr;
                write('How many numbers do you want to fill in? ');
                {Here we makes the user write in an answer for "forloop1"}
                readln(forloop1);
                {Calling for backup, procedure calculator}
                calculatorprocedure(forloop1);
                end;

readln;
{Here ends the main program which ends the whole program}
END.

I don't want to make you feel bad, but you need to start paying a whole lot more attention.

Your CalculatorProcedure makes two errors:
1. You are using a variable when defining your array's limits. Don't do that. That should prevent your code from compiling. I've already made a very explicit note about this. (And I don't care if GPC or FP let you get away with it... That is non-standard for BP and your professor will dock you points for it.)
2. You are looping with a variable named loop1, but you are accessing the array with a variable named j --which has a random value as you never assigned it one to begin with. Likewise, amount starts with a random value, so no matter what you add to it it will still be random when you are done.

Something you are having difficulty with is indentation. Indentation helps you understand your code. Let me show you what I mean:

procedure calculatorprocedure( forloop1_1: integer );
  var
    loop1, amount: integer;
    loop1loopnumbers: array[1..100] of integer;
  begin
    { You should set amount to something useful here }

    { Since loop1 is 1, 2, 3, ..., use it to index the array... }
    for loop1:=1 to forloop1_1 do begin
      write('Write a number: ');
      readln(loop1loopnumbers[loop1]);  { ...like this }
    end;
    writeln;

    { this next statement is in the wrong place. Currently,
      it only adds one of the entered numbers to amount. }
    amount:=amount+loop1loopnumbers[loop1];

    { Good: Tell the user what the amount entered was.
      Notice how I reworded the output to tell the user
      exactly what the amount is: the sum of the numbers. }
    Writeln('The sum of the numbers is ', amount);
  end;

Variable definitions that belong to the procedure's variable list are indented under the keyword var. Likewise, code statements that belong to the procedure body are indented between the keywords begin and end. Statements that belong to the loop are indented between for...begin and end. Now, take some time to read my comments, consider what exactly you are trying to do and how you are doing it, and see if you can't move things around a little to fix it.

In your program's begin..end block, it looks like you should be using a loop to:
1. clear the screen and print the menu
2. get a choice from the user
3. act on the user's choice
until the user chooses Q. There is a function called upcase that can help you there.

Also, those delay statements really, truly, indubitably, are a bad thing. Also, you don't need to tell the user what option he chose. He already knows. He'll just be annoyed that he has to press ENTER again.

Finally, you need to come up with better variable names. Choice in variable names shows either a firm understanding of what a piece of code should be doing, or a weak understanding. Right now you are a little over 1/3 of the way from weak to firm. For example, what does forloop1_1 mean? What does it do? If you name it numbers_to_input or something like that it becomes obvious what it is used for.

Remember, if you don't feel really stupid reading your code because it is so obvious what it does, then something is probably wrong.

Hope this helps.

-sorry for not listening last time, hopefully I paid fully attention this time:

{Procedure Calculator start}
         procedure calculatorprocedure(forloop1_1:integer);
         var {Procedure calculatorprocedure's variables}
            loop1,amount:integer;
            {array loop1loopnumbers}
            loop1loopnumbers:array[1..100] of integer;
         {Here starts the calculatorprocedure}
         begin
         amount:=0;
         {loop1 starts}
         for loop1:=1 to forloop1_1 do begin
         write('Write a number: ');
         readln(loop1loopnumbers[loop1]);
         {loop1 ends}
         end;
         writeln;
         amount:=amount+loop1loopnumbers[loop1];
         Writeln('Addition: The sum of the numbers is ',amount);          {<--- Needs fixes!}
         amount:=amount-loop1loopnumbers[loop1];
         Writeln('Subtraction: The sum of the numbers is ',amount);       {<--- Needs fixes!}
         amount:=amount*loop1loopnumbers[loop1];
         Writeln('Multiplication: The sum of the numbers is ',amount);      {<--- Needs fixes!}
         {Procedure Calculator end}
         end;

Gives me error when writing getting the sums. If I have said to loop 4 times and press 1 on every number thing it gives me "addition: 1", "subs and multi: 0"... hmm.. Help me out here (if you already havn't.. sorry)

Well, you're getting a little better. Watch your indentation.

What you need to do now is get out a piece of paper and pencil and draw yourself an array as a list of boxes big enough to write numbers in them.

Then draw yourself a box for the value of loop1. Put a 1 in the box. Write a number in the first box of the array. (It doesn't matter what number, any number will do: this is the number the user inputs.)

Now change the '1' in the loop1 box to 2, and repeat.

When you are done getting numbers from the user, (lines 11..15), you are left at line 16. Continue doing what each succeeding line does, referring to your boxes as necessary.

Good job on setting amount to zero. This works for addition and subtraction. But not multiplication. I suggest you stick to one operation at a time. Use one procedure to do addition. Another to do subtraction. Etc.

Good luck.

Thanks for the help. :)
Anyway I'm done with that selection now, it works well and goes really good, deleted some delays without the ones for the selections cause they were nice to have left. :)

Not I'm on the second selection, and there I need to get up with the string, to get the letters that were added for it and make it spelled, for example, backwards, so if you've entered for example "Loyen" I will be able to make it to "neyoL".. If you got time to tell me on an easy way, please do.

You can go backwards through a loop using the downto keyword:

procedure writeln_backwards( s: string );
  var i: integer;
  begin
    for i := length( s ) downto 1 do write( s[ i ] );
    writeln
  end;

Enjoy!

[Edit] Didn't saw that you've already answered. :D

Okay, I'm stuck with trying to get the string tell the name backwards.. :(

The name is in a relation. (shown below)

TYPE
{The relation for this program I'll be using}
name=record
Firstname:string;
Lastname:string;
end;

And I want it to tell me what the name is backward, like if I have written myname it will show me it like emanym, ok got it? My teacher says I need to make it to an array but then she didn't told me more.. :( She went away and helped others til' the end of the lesson so I'm asking you instead.

Sorry, forgotten you had already answered.
*moving on*

Thanks it worked, had problem, but I looked through my code and found the problem (missed a begin after "do begin" :P) Thanks guys!!:D:D

thanks guys, or mostly Duoas, I'm done with it (will get in latest 12December so). Thanks guys, really much. :):) I learned some more programming cause of you, I didn't knew about the lenght(stringname) before :)

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