Now we will focus on operations and strings We will learn also IF statement Let's start We will make a calculator using Pascal IF statement looks like this if -condition- then begin operations... end; But if there is many conditions it will look like this if -condition- then begin operations... end else if -condition2- then begin operations... end . . . else -other conditions- then begin operations... end; *** CALCULATOR *** program calc; uses wincrt; var x,y,res:integer; sel:char; BEGIN writeln('1. Addition'); writeln('2. Substraction'); writeln('3. Multiplication'); writeln(' Select: ');Readln(sel); write('Enter an integer a=');readln(a); write('Enter an integer b=');readln(b); if sel='1' then res=a+b else if sel='2' then res=a-b else if sel='3' then res=a*b else write('Invalid number.'); end.
In this lesson we will learn variables integer; real; char; string... Example: Integer: 25 4 -2 3 85 Real: 120.36 -9.66 45.12 Char: A B C D E f g h i j k l String: PASCAL programming Hello
we put variables after uses wincrt line. Example var Num1,Num2:Integer; Integers have ranges limits and types
Reals also have types:
You can use Real or Double. Operators in Pascal + Addition - Substraction * Multiplication / Division (Integer/real result) DIV Division (Integer result) MOD Division (Integer result the rest of division) > Superiour < Inferiour <> Differnce = Equality When we use variables we use in the main program readln to read the varible Example program test; uses wincrt; var Num1:Integer; begin write('Enter an integer'); readln(Num1); write(Num1); end.
Pascal
We will begin with simple programs. We begin with 'Hello World' program. As any languages has rules, grammar, syntax... Pascal has his own rules and you should obey it. The program name we write (program myfirstprog)we use begin in the program beginning and end on its ending but before that we write uses means using a library like wincrt which allow writing and reading variables. after we put BEGIN we want to show this message on computer screen "Hello World"so it will be like that write('Hello world');this is a line each line ends with ; The program will be like this: program myfirstprog; uses wincrt; BEGIN write('Hello World'); END. I think Pascal is the easiest programming language Install Pascal here