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

Thread Solved

Join Date: Apr 2007
Posts: 32
Reputation: adotl is an unknown quantity at this point 
Solved Threads: 0
adotl's Avatar
adotl adotl is offline Offline
Light Poster

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

 
0
  #1
Apr 24th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 27
Reputation: Terry Robinson is an unknown quantity at this point 
Solved Threads: 1
Terry Robinson Terry Robinson is offline Offline
Light Poster

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

 
0
  #2
Apr 25th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 32
Reputation: adotl is an unknown quantity at this point 
Solved Threads: 0
adotl's Avatar
adotl adotl is offline Offline
Light Poster

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

 
0
  #3
Apr 25th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 32
Reputation: adotl is an unknown quantity at this point 
Solved Threads: 0
adotl's Avatar
adotl adotl is offline Offline
Light Poster

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

 
0
  #4
Apr 25th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC