#K43312. Simple Calculator
Simple Calculator
Simple Calculator
This problem requires you to implement a simple calculator that processes arithmetic operations. Each operation is provided in a single line in the format \(a \ operator \ b\), where a and b are integers and operator can be one of the following: +
, -
, *
, or /
. For division, compute the result using integer division, i.e. output \(\lfloor \frac{a}{b} \rfloor\) if b is not zero. If an operation is invalid or cannot be parsed correctly, output an appropriate error message. The program terminates processing when a line with exactly "end" is encountered.
inputFormat
The input is read from standard input (stdin). Each line contains a single arithmetic operation in the format "a operator b". The input ends when a line exactly matching "end" is encountered.
outputFormat
For each valid operation (except the terminating "end"), output the result or an error message on a separate line to standard output (stdout). The expected error messages are as follows:
- If the operator is not one of
+
,-
,*
, or/
: output "Error: Invalid operator". - If the inputs cannot be parsed as two integers followed by a valid operator: output "Error: Invalid input".
- If division by zero is attempted: output "Error: Division by zero".
3 + 4
10 - 5
6 * 7
8 / 2
10 / 0
end
7
5
42
4
Error: Division by zero
</p>