program Calculation;
uses crt;
var menu,n1,n2: integer;
function p(n1,n2: integer): real;
begin
p:=n1+n2;
end;
function mi(n1,n2: integer): real;
begin
mi:=n1-n2;
end;
function mul(n1,n2: integer): real;
begin
mul:=n1*n2;
end;
function divi(n1,n2: integer): real;
begin
divi:=n1/n2;
end;
function sqroot(n1: integer): real;
begin
sqroot:=sqrt(n1);
end;
function sqpow(n1: integer): real;
begin
sqpow:=sqr(n1);
end;
{PROCEDURE}
procedure table;
var tn: integer;
q: char;
begin
repeat
clrscr;
writeln('Multiply Table');
writeln;
write('Put a number : ');
readln(tn);
clrscr;
writeln(tn,' x 1 = ',tn*1);
writeln(tn,' x 2 = ',tn*2);
writeln(tn,' x 3 = ',tn*3);
writeln(tn,' x 4 = ',tn*4);
writeln(tn,' x 5 = ',tn*5);
writeln(tn,' x 6 = ',tn*6);
writeln(tn,' x 7 = ',tn*7);
writeln(tn,' x 8 = ',tn*
;
writeln(tn,' x 9 = ',tn*9);
writeln(tn,' x 10 = ',tn*10);
writeln(tn,' x 11 = ',tn*11);
writeln(tn,' x 12 = ',tn*12);
repeat
writeln;
write('Return to Main Menu? (y/n) : ');
readln(q);
if (q='y') or (q='n') then begin writeln; end
else begin writeln('Invalid Choice');
end;
until (q='y') or (q='n');
until q='y';
end;
procedure plus;
var q: char;
begin
repeat
clrscr;
writeln('Plus Calculation');
writeln;
write('Put first number : ');
readln(n1);
writeln;
write('Put second number : ');
readln(n2);
writeln;
writeln;
writeln(n1,' + ',n2,' = ',p(n1,n2):9:2);
repeat
writeln;
write('Return to Main Menu? (y/n) : ');
readln(q);
if (q='y') or (q='n') then begin writeln; end
else begin writeln('Invalid Choice');
end;
until (q='y') or (q='n');
until q='y';
end;
procedure minus;
var q: char;
begin
repeat
clrscr;
writeln('Minus Calculation');
writeln;
write('Put first number : ');
readln(n1);
writeln;
write('Put second number : ');
readln(n2);
writeln;
writeln;
writeln(n1,' - ',n2,' = ',mi(n1,n2):9:2);
repeat
writeln;
write('Return to Main Menu? (y/n) : ');
readln(q);
if (q='y') or (q='n') then begin writeln; end
else begin writeln('Invalid Choice');
end;
until (q='y') or (q='n');
until q='y';
end;
procedure multi;
var q: char;
begin
repeat
clrscr;
writeln('Multiply Calculation');
writeln;
write('Put first number : ');
readln(n1);
writeln;
write('Put second number : ');
readln(n2);
writeln;
writeln;
writeln(n1,' x ',n2,' = ',mul(n1,n2):9:2);
repeat
writeln;
write('Return to Main Menu? (y/n) : ');
readln(q);
if (q='y') or (q='n') then begin writeln; end
else begin writeln('Invalid Choice');
end;
until (q='y') or (q='n');
until q='y';
end;
procedure divide;
var q: char;
begin
repeat
clrscr;
writeln('Divide Calculation');
writeln;
write('Put first number : ');
readln(n1);
writeln;
write('Put second number : ');
readln(n2);
writeln;
writeln;
writeln(n1,' / ',n2,' = ',divi(n1,n2):9:2);
repeat
writeln;
write('Return to Main Menu? (y/n) : ');
readln(q);
if (q='y') or (q='n') then begin writeln; end
else begin writeln('Invalid Choice');
end;
until (q='y') or (q='n');
until q='y';
end;
procedure sqt;
var q: char;
begin
repeat
clrscr;
writeln('Square Root Calculation');
writeln;
write('Put a number : ');
readln(n1);
writeln;
writeln('Square Root of ',n1,' is ',sqroot(n1):9:2);
repeat
writeln;
write('Return to Main Menu? (y/n) : ');
readln(q);
if (q='y') or (q='n') then begin writeln; end
else begin writeln('Invalid Choice');
end;
until (q='y') or (q='n');
until q='y';
end;
procedure sq;
var q: char;
begin
repeat
clrscr;
writeln('Square Power Calculation');
writeln;
write('Put a number : ');
readln(n1);
writeln;
writeln('Square Power of ',n1,' is ',sqpow(n1):9:2);
repeat
writeln;
write('Return to Main Menu? (y/n) : ');
readln(q);
if (q='y') or (q='n') then begin writeln; end
else begin writeln('Invalid Choice');
end;
until (q='y') or (q='n');
until q='y';
end;
procedure circle;
var r: char;
area: real;
begin
clrscr;
write('input you reader = ');
readln(r);
area:=3.14;
writeln('this area of circle = ',area:1:2);
readln;
end;
procedure trigle;
var high,base:integer;
begin
clrscr;
write('input your base = ');
readln(base);
write('inpuut your high = ');
readln(high);
clrscr;
write('area of triangle = ',0.5*base*high:1:2);
readln;
end;
{MAIN PROGRAM}
begin
repeat
clrscr;
writeln('CALCULATOR PROGRAM');
writeln;
writeln;
writeln('Select one..');
writeln;
writeln('1.Multiply Table');
writeln('2.Plus Calculation');
writeln('3.Minus Calculation');
writeln('4.Multiply Calculation');
writeln('5.Divide Calculation');
writeln('6.Square Root Calculation');
writeln('7.Square Calculation');
writeln('8.Area of circle');
writeln('9.Area of triangle');
writeln('0.Exit');
writeln;
write(': ');
writeln;
writeln;
writeln;
writeln(' Made by: jittatarn yonsombat M.3/1 No:11');
gotoxy(3,15);
readln(menu);
case menu of
0:writeln;
1:table;
2:plus;
3:minus;
4:multi;
5:divide;
6:sqt;
7:sq;
else writeln;
writeln('Invalid Choice');
readln;
end;
until menu=0;
clrscr;
readln;
end.
ลองทำออกมาดูเเต่2โปรเเกรมสุดท้ายมัยใช้ไม่ได้อะครับช่วยดูให้หน่อยนะครับ