954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pascal : Cant see why program wont run, exits with error.

Im failing to see what Ive done wrong, the syntax is right but the program wont run for me when I enter in a the else statement works tho....

program Word (input, output);
uses crt;
   var
      number : integer;
      letter: string;
   begin
      {------------Introduction & Setup------------------}
      clrscr;
      {------VERY User-Friendly------}
      Repeat
         writeln('Whats the right letter? ');
         readln(number);
         str(number,letter);
         if (letter ='a') then
            writeln('Correct Answer ')
         else
            writeln(' a needs to be entered');
      Until (letter = 'a');
      {-------------------Printing Results------------------}
      writeln('The answer is ', letter);
      readln;
   end.



Any ideas? Im guessing its something stupid, I just cant seem to see it at the moment.

adotl
Light Poster
33 posts since Apr 2007
Reputation Points: 17
Solved Threads: 0
 

You didn't say what Pascal you are using, but typically readln expects a text variable and you are passing an integer. If the point is to read in an ASCII code and then print out the character, you need to read in the text, convert it to an integer and then convert the integer to the character.

Terry Robinson
Light Poster
27 posts since Apr 2007
Reputation Points: 12
Solved Threads: 1
 

Im using Free Pascal and thanks I hadnt noticed that.

There was another work around that I did with just setting the value as string as when a number is entered the program doesnt crash unlike with the reverse of a string being entered when the variable is an integer.

adotl
Light Poster
33 posts since Apr 2007
Reputation Points: 17
Solved Threads: 0
 

This is the solution I came up with a few minutes ago....

program Word (input, output);
uses crt;
   var
      letter: string;
   begin
      {------------Introduction & Setup------------------}
      clrscr;
      {------VERY User-Friendly------}
      Repeat
         writeln('Whats the right letter? ');
         readln(letter);
         if (letter = 'a') OR (letter = 'b') then
            writeln('Correct Answer ')
         else
            writeln(' a needs to be entered');
      Until (letter =UPCASE('a')) OR (letter = 'b');
      {-------------------Printing Results------------------}
      writeln('The answer is ', letter);
      readln;
   end.
adotl
Light Poster
33 posts since Apr 2007
Reputation Points: 17
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You