User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 391,700 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,172 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser:
Views: 872 | Replies: 3 | Solved
Reply
Join Date: Apr 2007
Location: Glasgow
Posts: 32
Reputation: adotl is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
adotl's Avatar
adotl adotl is offline Offline
Light Poster

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

  #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....

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.
Last edited by adotl : Apr 24th, 2007 at 6:38 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2007
Posts: 27
Reputation: Terry Robinson is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Terry Robinson Terry Robinson is offline Offline
Light Poster

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

  #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  
Join Date: Apr 2007
Location: Glasgow
Posts: 32
Reputation: adotl is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
adotl's Avatar
adotl adotl is offline Offline
Light Poster

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

  #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  
Join Date: Apr 2007
Location: Glasgow
Posts: 32
Reputation: adotl is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
adotl's Avatar
adotl adotl is offline Offline
Light Poster

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

  #4  
Apr 25th, 2007
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Pascal and Delphi Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 2:41 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC