Objective

Extend the program created in the previous Rudimentary Arithmetic exercise, to enable recomputation of any operation on two given values.

Difficulty

Very easy

Description

In the previous exercise, we constructed a program that could perform one of a given list of operations on two input integers. However, as you many know, it was only possible to do this once.

After the first computation, the program ended and likewise we couldn't continue on with other computations, apart from having to rerun the program.

Now, you need to make a couple of modifications to the previous program so that it could perform as many computations as the user wants to, and then stop when the user is done with the computations.

The initial inputs of this program are same as those for the previous exercise.

However, when the output for the first computation is made (which is again the same as in the previous exercise), you should then ask the user the following question, after leaving a blank line.

Restart? y for Yes, n for No.

If the user inputs 'y', continue repeating the steps of the program after a blank line. In contrast, if the user inputs 'n', halt the program — no more computations could be performed now.

Below shown is a detailed example.

x: 10
y: 20
Operation: a
x + y = 30

Restart? y for Yes, n for No.
y

x: 65
y: 15
Operation: s
x - y = 50

Restart? y for Yes, n for No.
n

Take note of the blank lines in the shell snippet here. You must make sure that your code also gives them.

A blank line following the input for 'Restart? y for Yes, n for No.' should only be given if the user enters 'y' i.e. a new computation is begun after leaving a blank line. But if the user enters 'n', then your program should end immediately, without leaving a blank line.