1. create Simple_Calculator.sh
@echo off
echo Simple Calculator
set /p "num1=Enter first number: "
set /p "num2=Enter second number: "
set /p "operator=Enter operator (+, -, *, /): "
if "%operator%"=="+" (
set /a "result=num1 + num2"
) else if "%operator%"=="-" (
set /a "result=num1 - num2"
) else if "%operator%"=="*" (
set /a "result=num1 * num2"
) else if "%operator%"=="/" (
set /a "result=num1 / num2"
) else (
echo Invalid operator
exit /b 1
)
echo Result: %result%
2. run
d:\tmp>Simple_Calculator.bat
Simple Calculator
Enter first number: 100
Enter second number: 200
Enter operator (+, -, *, /): +
Result: 300
d:\tmp>Simple_Calculator.bat
Simple Calculator
Enter first number: 100
Enter second number: 200
Enter operator (+, -, *, /): -
Result: -100
d:\tmp>Simple_Calculator.bat
Simple Calculator
Enter first number: 100
Enter second number: 400
Enter operator (+, -, *, /): *
Result: 40000
d:\tmp>Simple_Calculator.bat
Simple Calculator
Enter first number: 100
Enter second number: 400
Enter operator (+, -, *, /): /
Result: 0
d:\tmp>
3. capture result
No comments:
Post a Comment