Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.
X

How to get your Pascal Code to work on MacOX

A friend wanted me to help with some assignments on Pascal and it really got funny how I couldn't easily install the compiler on MacOx so I decided to put up some blog post for someone who would also like to do same.

You would need Xcode to be installed before FPC is installed. Visit Free Pascal (http://www.freepascal.org/download.var) and download the installation file. Double click on the .dmg and follow the prompt to install.  It will be installed in /usr/local/bin.

The compiler is called "fpc". Type "fpc" on the terminal and you get a screen like this, then you know your installation was fine.

I wrote a program to calculate the CGPA (Cummulative Grade Point Average) of Students in Pascal. You can find it below for a head start.


	Program CGPA_Calculator;
    
    var
    
    units, semesters, i, numerator : integer;
    denominator, cgpa, gpa : real;
    
Begin

    denominator := 0;
    numerator := 0;
    
    writeln('Welcome to Pascal CGPA Calculator!');
    writeln('How many semester are you calculating for?');
    
    readln(semesters);
    
    for i := 1 to semesters do
    
    Begin
    
        writeln('Enter semester ', i, ' GPA');
        readln(gpa);
        
        writeln('Enter semester ', i, ' Unit');
        readln(units);
        
        denominator :=  denominator + (gpa * units);
        numerator := numerator + units;
        
    End;
    
    cgpa := denominator / numerator;
    
    writeln('Your CGPA is ', cgpa:5);
    
End.

This is just a sample code I decided to play around with. Hope it is helpful.


comments powered by Disqus