Challenge: Making a Calculator
In this exercise, you are required to implement a calculator by using Switch statements.
We'll cover the following...
Problem Statement
Write a code which will take:
-
Two variables named
num1
andnum2
-
a
string
type variable calledOperator
which will be passed as input to our switch statement. -
The
Operator
variable can be passed the following:+
,-
,*
and/
-
Use
switch
statements to compute:- addition,
- subtraction,
- multiplication
- division
Note: For the default case, simply print the statement
echo "Wrong operator";
.
Sample Input
num1 = 5.5
num2 = 6.5
Operator = '+'
Sample Output
Output = 12