Practice
Simple Calculator
2021/Oct/Nov·Variant 2
EASYSelection
Write an algorithm that acts as a simple calculator. It should first read an integer Operator representing the chosen operation (1 for addition, 2 for subtraction, 3 for multiplication, 4 for division). Then, it reads two numbers, Value1 and Value2. It performs the chosen operation on the two numbers and outputs the result.
Input: An integer Operator (1 to 4), followed by two real numbers Value1 and Value2.
Output: A single number representing the result of the calculation.
Example:
Input: 1
5.5
10
Output: 15.5
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Addition
Inputs: 1, 5.5, 10
Expected: 15.5
Test 2: Subtraction
Inputs: 2, 10, 4
Expected: 6
Ctrl+Enter
Press Ctrl+Enter to run your code
or Ctrl+Shift+Enter to check