Computer Sciences

This blog gives you informations about internet, programming and computing news...

vendredi 1 juillet 2016

PASCAL - Lesson 3

PROGRAMMING PASCAL

LESSON 2


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.





Aucun commentaire:

Enregistrer un commentaire