Visual
HomeAboutCreateSign in Русский

calculate

MODULE Calculator;

IMPORT In, Out;

VAR
a, b, result: REAL;
operation: INTEGER;

PROCEDURE Add(x, y: REAL): REAL;
BEGIN
RETURN x + y;
END Add;

PROCEDURE Subtract(x, y: REAL): REAL;
BEGIN
RETURN x - y;
END Subtract;

PROCEDURE Multiply(x, y: REAL): REAL;
BEGIN
RETURN x * y;
END Multiply;

PROCEDURE Divide(x, y: REAL): REAL;
BEGIN
IF y = 0.0 THEN
Out.String("Error: Division by zero");
RETURN 0.0;
ELSE
RETURN x / y;
END;
END Divide;

BEGIN
Out.String("Simple Arithmetic Calculator");
Out.Ln;

(* User input *)
Out.String("Enter the first number: ");
In.Real(a);

Out.String("Enter the second number: ");
In.Real(b);

Out.String("Select operation (1: Add, 2: Subtract, 3: Multiply, 4: Divide): ");
In.Int(operation);

(* Perform the selected operation *)
CASE operation OF
1: result := Add(a, b);
2: result := Subtract(a, b);
3: result := Multiply(a, b);
4: result := Divide(a, b);
ELSE
Out.String("Invalid operation selected.");
result := 0.0;
END;

(* Output result *)
Out.String("Result: ");
Out.Real(result, 0);
Out.Ln;

END Calculator.

saidmurodovamehrigiyo
Oberon & OberonJSSource code
Result  

check indices in arrays

Project modules:
Init
Framework modules:
Log Docu
Draw Docu
Math Docu
Strings Docu
Forms Docu
Plot Docu
Out Docu
In Docu