RSS Forums RSS
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 4547 | Replies: 7
Reply
Join Date: Jun 2003
Location: Malaysia
Posts: 313
Reputation: red_evolve is on a distinguished road 
Rep Power: 6
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Pascal starter.

  #1  
Feb 2nd, 2004
Hi.

First of all, I'd like to apologize for I really do not know where to post this thread to. :lol: I know Pascal is out but apparently I have got to pick up this language in order to finish my project.

What I'd like to ask is whether Pascal offers exception handling. I'd like to read an integer but I've to consider the chances of users keying in a non-integer value. I've checked different sites which offer free online tutorial but to no avail. Please help. Thank you.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2004
Posts: 1,514
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Rep Power: 10
Solved Threads: 49
Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: Pascal starter.

  #2  
May 3rd, 2004
Hello,

I am not certain if this thread is alive or not, but if you are still out there, Please post your code and let's look at this. I enjoyed Pascal a lot in college, and wish I could still use it instead of C/C++ when I have to occasionally code.

Christian
Reply With Quote  
Join Date: Jun 2003
Location: Malaysia
Posts: 313
Reputation: red_evolve is on a distinguished road 
Rep Power: 6
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Pascal starter.

  #3  
Jun 14th, 2004
Greetings.
A thousand apologies.
I was browsing through some old threads and I accidentally bump into my own old thread. :cheesy:
I had eventually gave up on exception handling because I still cannot figure out the way. However, if you know, I'd like to learn it. Thanks a lot.

Program FactorialCalculator;

uses crt;
var input : integer;

function calculate(num:integer):integer;
begin
if ((num = 0) or (num = 1)) then
calculate := 1
else
calculate := calculate(num-1) * num;
end;

begin
writeln;
writeln;
writeln('*** FACTORIAL CALCULATOR ***');
writeln('Enter integer: ');
readln(input);
writeln('The factorial of ',input,' is ',calculate(input));

end.

That was a small program that I got to write using Pascal as a starter.
I'd like to handle the exception where the prompt for an input from the user goes. I only want an integer here.
Any idea?
Reply With Quote  
Join Date: Mar 2004
Posts: 1,514
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Rep Power: 10
Solved Threads: 49
Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: Pascal starter.

  #4  
Jun 15th, 2004
Hello,

Unfortunately, my Pascal things are in another city. Grr. What happens if you input a letter? Does the program substitute the ASCII value of the letter instead? Hmm. I am wondering if you should accept a string, and then convert it to numeric. I have to see if that function is even available in Pascal.

Wow, I am out of date here.

Christian
Reply With Quote  
Join Date: Jun 2003
Location: Malaysia
Posts: 313
Reputation: red_evolve is on a distinguished road 
Rep Power: 6
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Pascal starter.

  #5  
Jun 15th, 2004
Greetings.

Alright. It's ok. I'm just glad that after so long, there is actually a reply from someone.

I'm in my office right now ( Industrial Training ). I'll check with my pascal compiler once I get home later in the night.
What happens if you input a letter? Does the program substitute the ASCII value of the letter instead?
Thanks anyway, Christian.
Reply With Quote  
Join Date: Oct 2004
Posts: 36
Reputation: nikkisboricua is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
nikkisboricua's Avatar
nikkisboricua nikkisboricua is offline Offline
Light Poster

Solution Re: Pascal starter.

  #6  
Nov 5th, 2004
hey, im a pascal starter too. instead of this:

var input : integer;

try using this :

var input :real;

yea. i just learned that last week.

integer is a whole number
real is a whole or decimal. but if you put a decimal, REMEMBER to enter it like so: 0.6
Reply With Quote  
Join Date: Jan 2005
Posts: 31
Reputation: Jackrabbit is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Jackrabbit Jackrabbit is offline Offline
Light Poster

Re: Pascal starter.

  #7  
Jan 12th, 2005
program FactorialCalculator;

{$APPTYPE CONSOLE}

uses
   SysUtils;

var
   input : string;
   value : Integer;

function calculate( num : integer ) : integer;
begin
   if ( ( num = 0 ) or ( num = 1 ) ) then
      calculate := 1
   else
      calculate := calculate( num - 1 ) * num;
end;

begin
   writeln;
   writeln;
   writeln( '*** FACTORIAL CALCULATOR ***' );
   repeat
      write( 'Enter integer: ' );
      readln( input );
   until TryStrToInt( input, value );
   writeln( 'The factorial of ', input, ' is ', calculate( value ) );
end.
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,749
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Pascal starter.

  #8  
Jan 13th, 2005
Whether you get exception handling or not depends on the flavour of Pascal you're working with.

Delphi (which is Pascal with a nice IDE and stuff) for example has a comprehensive exception mechanism (though it might not have been available in the very early versions, I don't have those here to check).

Other dialects may have duplicated this over time (Borland being the de-facto standard for Pascal in lue of an official standards body).
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)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:34 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC