Learn Pascal Programming with Mc Kenzie

Let's make this lesson more interesting with an exercise. I hope you are not afraid of a little arithmetic. I'll keep the numbers small so let's try solving a simple problem.

What if you wanted to instruct Pascal to calculate and print 10% of 500. How would you go about doing that?

Think of the statement that you should use. Ten percent is really 10/100 or put another way 0.10

The zero before the point is important to Pascal so it should not be omitted. As far as Pascal is concerned 0.10 is correct and .10 is wrong. Have you come up with the answer yet?

Welcome to the Pascal World!

 

Exercise No 1

A pascal statement to calculate 10% of 500 should be written as Writeln(500 * 0.10); or Writeln(0.10 * 500 );

Remember to include the semi-colon at the end of the statement.

If you did not get that one correct then how about this one : Write a Pascal statement to calculate and print 15 percent Value Added Tax (VAT) on an item costing Three Hundred dollars ($300.00).

The answer can be found in the next program. It is the first writeln statement. The second writeln statement is not necessary for solving the problem but I included it in preparation for the next lesson so don't let it confuse you. You can leave it out completely and Pascal will still give you the correct output.

program vat(output);
begin
   writeln(300 * 0.15);
   writeln('My Vat Program')
   end.

This program also has two parts.

1. The Program Heading
2. The Body

1.0   The Program Heading starts with the word PROGRAM followed by the name of the program. The name of this program is VAT. The heading ends with a semi-colon.

Here is a second version of the same program :

program vatV2;
begin
   writeln(300 * 0.15);
   writeln('My Vat Program')
   end.


2.0    The body of the program starts with BEGIN followed by two writeln statements and ends with the word END. Please remember that statements end with the semi-colon but the program ends with a full stop after the word END.

    The output from the first line is what is important in this exercise. Perhaps this was too easy for you. The program only prints the VAT amount.

Your Turn

I am going to step it up a notch. Write another VAT program. Call it VATPROV3 for Value Added Program Version Three. This time calculate and print the final price a customer pays for an item costing Five Hundred Dollars ($500) plus VAT at 15%. Use only one writeln statement.

BSS Main | Previous Lesson | Next Lesson |