• Lenguaje

    Pascal

  • Descripción

    Calculadora que suma, resta, multiplica y divide

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
program CalculadoraQueSumaRestaMultiplicaYDivide;
uses crt;

var operacion : integer;
var a, b, resultado : real;
var tecla_repetir : char;
begin
    repeat
        clrscr;
        write ('Ingresa el valor de a: ');
        readln (a);
        write ('Ingresa el valor de b: ');
        readln (b);
        writeln ('Selecciona el valor de operacion.');
        writeln ('    1.- Suma');
        writeln ('    2.- Resta');
        writeln ('    3.- Multiplicaci'#162'n');
        writeln ('    4.- Divisi'#162'n');
        write ('    : ');
        repeat
            readln (operacion);
            if (operacion<1) or (operacion>4) then
                write ('Valor incorrecto. Ingr'#130'salo nuevamente.: ');
        until (operacion>=1) and (operacion<=4);
        resultado := 0;
        if operacion=1 then
            begin
                resultado := a+b;
            end;
        if operacion=2 then
            begin
                resultado := a-b;
            end;
        if operacion=3 then
            begin
                resultado := a*b;
            end;
        if (operacion=4) and (b<>0) then
            begin
                resultado := a/b;
            end;
        writeln ('Valor de resultado: ', resultado:0:6);
        writeln;
        write (#168'Deseas repetir el proceso? (S/N): ');
        repeat
            tecla_repetir := readkey;
        until (tecla_repetir = 's') or (tecla_repetir = 'n') or (tecla_repetir = 'S') or (tecla_repetir = 'N');
    until (tecla_repetir <> 's') and (tecla_repetir <> 'S');
end.