Objective

Extend the program created in the previous Addition Calculator exercise to perform any given operation on the input numbers, not just addition.

Difficulty

Easy

Description

Back in the Addition Calculator exercise, we created a program to add two input numbers.

Now you need to extend that program and perform any given operation on the two input numbers, other than just addition. The desired operation is itself specified as an input value.

As before, we begin with asking the user to enter two numbers, and then ask for the desired operation.

Shown below is the general form of the initial three input prompts of the program:

x: <input>
y: <input>
Operation: <operation>

Where <input> denotes a number and <operation> denotes a letter to specify the operation desired to be performed on x and y. <operation> must be one of the following characters:

  1. a for addition.
  2. s for subtraction.
  3. m for multiplication.
  4. d for division.
  5. e for exponentiation.
  6. r for remainder.

Finally, when all of the inputs are received, the program should output the following after leaving a blank line, if the given operation character was one of those mentioned above:

<x> <operation_symbol> <y> = <result>

where <x> and <y> are the input numbers x and y respectively, <operation_symbol> is the symbol to denote the corresponding operation in PHP, and <result> is the result of the operation (as performed on x and y).

If the input operation character wasn't one of those mentioned above, then the program should simply output the text 'Unknown operation.', once again with a blank line before itself.

Shown below is an example:

x: 10
y: 20
Operation: a

10 + 20 = 30

Here's another example:

x: 50
y: 7
Operation: m

50 * 7 = 350

And yet another example:

x: 100
y: 8
Operation: b

Unknown operation.

Take note of the blank line after the Operation: ... prompt in all these examples. Your code must produce this blank line.