0

I wrote some vbscript code for the following assignment: "Develop a math calculator with the following functions: Add two numbers, Subtract, Multiply two numbers, Division, X to the Power of Y.Ask the user to enter two numbers using input boxes and also the operation to be performed. Display the result as a message."

While running the code the addition function does not work as expected. It concatenates the numbers entered in the inputbox. Also the power function doesnt work either. Subtraction, multiplication and division work flawlessly. What could be the issue?

dim x, y, result, operation

x = InputBox("Enter the first number: ")
y = InputBox("Enter the second number: ")
operation = InputBox("Enter the operation you want to perform: ")

if operation = "Add" then 
    WScript.echo("Your result is :" & Add(x,y))
elseif operation = "Subtract" then 
    WScript.echo ("Your result is : " & Subtract(x,y))
ElseIf operation = "Multiply" Then
    WScript.echo ("Your result is : " & Multiply(x,y))
ElseIf operation = "Divide" Then
    WScript.echo("Your result is : " & Divide(x,y))
ElseIf operation = "Power" Then
    WScript.echo("Your result is :" & Power(x,y))
End if

Function Add(inta, intb)
    Add = inta + intb
End Function
    
'subtract

Function Subtract(inta, intb)
    Subtract = inta - intb
End Function

'multiply

Function Multiply(inta, intb)
    Multiply = inta * intb
end Function

' divide

Function Divide(inta,intb)
    Divide = inta / intb
end Function

'power

Function Power(inta,inb)
    Power = inta ^ intb
end Function

0 Answers0