944,047 Members | Top Members by Rank

Ad:
Apr 24th, 2007
0

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

Expand Post »
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....

Pascal and Delphi Syntax (Toggle Plain Text)
  1. program Word (input, output);
  2. uses crt;
  3. var
  4. number : integer;
  5. letter: string;
  6. begin
  7. {------------Introduction & Setup------------------}
  8. clrscr;
  9. {------VERY User-Friendly------}
  10. Repeat
  11. writeln('Whats the right letter? ');
  12. readln(number);
  13. str(number,letter);
  14. if (letter ='a') then
  15. writeln('Correct Answer ')
  16. else
  17. writeln(' a needs to be entered');
  18. Until (letter = 'a');
  19. {-------------------Printing Results------------------}
  20. writeln('The answer is ', letter);
  21. readln;
  22. end.
Any ideas? Im guessing its something stupid, I just cant seem to see it at the moment.
Last edited by adotl; Apr 24th, 2007 at 7:38 pm.
Similar Threads
Reputation Points: 17
Solved Threads: 0
Light Poster
adotl is offline Offline
31 posts
since Apr 2007
Apr 25th, 2007
0

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

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.
Reputation Points: 12
Solved Threads: 1
Light Poster
Terry Robinson is offline Offline
27 posts
since Apr 2007
Apr 25th, 2007
0

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

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.
Reputation Points: 17
Solved Threads: 0
Light Poster
adotl is offline Offline
31 posts
since Apr 2007
Apr 25th, 2007
0

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

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

Pascal and Delphi Syntax (Toggle Plain Text)
  1. program Word (input, output);
  2. uses crt;
  3. var
  4. letter: string;
  5. begin
  6. {------------Introduction & Setup------------------}
  7. clrscr;
  8. {------VERY User-Friendly------}
  9. Repeat
  10. writeln('Whats the right letter? ');
  11. readln(letter);
  12. if (letter = 'a') OR (letter = 'b') then
  13. writeln('Correct Answer ')
  14. else
  15. writeln(' a needs to be entered');
  16. Until (letter =UPCASE('a')) OR (letter = 'b');
  17. {-------------------Printing Results------------------}
  18. writeln('The answer is ', letter);
  19. readln;
  20. end.
Reputation Points: 17
Solved Threads: 0
Light Poster
adotl is offline Offline
31 posts
since Apr 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Pascal : Variable for both integer & string?
Next Thread in Pascal and Delphi Forum Timeline: help me plssss





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC