Aim : Create the equivalent of a four-function calculator. The program should request the user to enter a number, an operator and another number. It should then carry out the specified arithmetical operation: adding, subtracting, multiplying or dividing the two numbers (It should use a switch statement to select the operation). Finally, it should display the result. When it finishes the calculation, the program should ask if the user wants to do another calculation. The response can be Y or N. Some sample interaction with the program might look like this: Enter first number, operator, second number: 10/ 3 Answer = 3.333333 Do another (Y/ N)? Y Enter first number, operator, second number 12 + 100 Answer = 112 Do another (Y/ N)? N

Theory

Input Handling

The user enters a mathematical expression in the format:
number1 operator number2 (e.g., 10 / 3).
The program takes three inputs:
number1 (first operand)
operator (+, -, *, /) number2 (second operand)

2. Using the switch Statement for Operation Selection

The switch statement is used to choose the correct operation based on the entered Each case performs the respective arithmetic operation.
Example: If the user inputs +, the program executes the addition case.

3. Performing Arithmetic Operations

Addition (+): result = number1 + number2
Subtraction (-): result = number1 - number2
Multiplication (*): result = number1 * number2
Division (/): result = number1 / number2
Special Handling: If number2 is 0, the program should display an error message (Division by zero is not allowed).

4. Looping for Multiple Calculations (do-while Loop)

After displaying the result, the program asks: "Do another (Y/N)?"
If the user enters Y, the program repeats.
If N, the program terminates.
A do-while loop is used to ensure the calculator runs at least once.

5. Error Handling and Validation

Checking for division by zero.
Ensuring the user enters a valid operator (+, -, *, /).
Accepting only valid numerical inputs.
Program :

Conclusion : Hence we have performed our practical successfully