Im trying to create a batch that will calculate a certain equation with Input variables.
equation is
(%b%+(%b%*(88/100))+(%b%*(165/100))+(%b%*(%r%/100)))*%c%
im currently using code i found here but it doesn't seem to work properly
SETLOCAL EnableExtensions EnableDelayedExpansion
#echo off
echo Enter BaseCC
set /P b=
echo Enter Riven ( if none enter 1 )
set /P r=
echo Enter Combo Multiplier
set /P c=
call :calc_ 2 (%b%+(%b%*(88/100))+(%b%*(165/100))+(%b%*(%r%/100)))*%c%
echo !calc_v!
pause
goto :EOF
:calc_
set scale_=1
set calc_v=
for /l %%i in (1,1,%1) do set /a scale_*=10
set /a "calc_v=!scale_!*%2"
set /a calc_v1=!calc_v!/!scale_!
set /a calc_v2=!calc_v!-!calc_v1!*!scale_!
set calc_v=!calc_v1!.!calc_v2!
goto :EOF
if b is 20; r is 114; c is 3
result should be 280.2
The result i get is 180.0
#ECHO OFF
SETLOCAL
rem equation is (%b%+(%b%*(88/100))+(%b%*(165/100))+(%b%*(%r%/100)))*%c%
echo Enter BaseCC
set /P b=
echo Enter Riven ( if none enter 1 )
set /P r=
echo Enter Combo Multiplier
set /P c=
:: Calculate (%b%+(%b%*(88/100))+(%b%*(165/100))+(%b%*(%r%/100)))*%c%
:: write this in FP terms : (b+0.88b+1.65b+(br/100))*c
:: Resolve to (3.53b+(br/100))*c = (353b+br)*c/100
:: = (353+r)*b*c /100
SET /a result_by_100=(353+r)*b*c
ECHO result=%result_by_100:~0,-2%.%result_by_100:~-2%
GOTO :EOF
The problem is that the term (%b%+(%b%*(88/100))+(%b%*(165/100))+(%b%*(%r%/100)))*%c% is resolved using integer-maths, so each term which implements a division is resolved to int(term). The result is `(%b%+(%b%*INT(88/100))+(%b%*INT(165/100))+(%b%INT(%r%/100)))%c%
The simple solution is to resolve the formula as shown.
Found the solution thanks to the suggestions of Stephan.
it works correctly now.
Didn't know i can implement vbs.
#echo off
set /p b=BaseCC=
set /p r=Riven=
set /p c=Combo=
echo WSH.Echo Eval(Wscript.Arguments(0))>>Q.vbs
cscript //nologo Q.vbs ((%b%+(%b%*(88/100))+(%b%*(165/100))+(%b%*(%r%/100)))*%c%)
Del "Q.vbs"
Pause>nul
Related
I have a project for square root calculation to get the larger side of in a right triangle using Pythagorean theorem.
Here's what I've tried :
#echo off
set /p a=Pleas Enter Value(1) =
echo.
set /p b=Pleas Enter Value(2) =
set /a c=%a%*%a%
set /a d=%b%*%b%
set /a F=%d%+%c%
echo.
:calculation Value(3)
rem root Number
√%F%
echo.
pause>nul
Batch
This is the native batch method(not accurate):
set divider=0
:loop
set /a divider=divider+1
set /a sqrt=F / divider
if %divider% equ %sqrt% goto break
if %divider% gtr %sqrt% goto break
goto loop
:break
echo %sqrt%
It will floor the number if the square root is floating point number.
Again, will not support floating point arithmetic, but this code works:
#echo off
Title SquareRoot
:StartSquareRoot
cls
echo Number:
set /p number=
call :SquareRoot %number%
echo Square: %number%
echo Root: %answer%
pause
goto StartSquareRoot
:SquareRoot
set root=1
set /a sqr=%root%*%root%
:Loop
if %sqr% LSS %number% (
set /a root=root+1
set /a sqr=root*root
goto Loop
)
(EndLocal && set answer=%root% && exit /B)
This is a simple calculator:
#ECHO OFF
TITLE Simple Calculator
ECHO if you want to add press 1,subtract 2,multiply 3 and divide 4
set /a selection =
if %selection%== "1" goto add
if %selection%== "2" goto sub
if %selection%== "3" goto multiply
if %selection%== "4" goto divide
:add
ECHO Type the first number you wish to add:
SET /P Numadd1=
ECHO Type the second number you want to add to the first number:
SET /P Numadd2=
ECHO.
SET /A Ansadd=%Numadd1%+%Numadd2%
ECHO The result is: %Ansadd%
ECHO.
ECHO Press any key to exit.
PAUSE>nul
:sub
ECHO Type the first number you wish to subtract with:
SET /P Numsub1=
ECHO Type the second number you want to subtract from %Numsub1%:
SET /P Numsub2=
ECHO.
SET /A Ansub=%Numsub1%-%Numsub2%
ECHO The result is: %Ansub%
ECHO.
ECHO Press any key to exit.
PAUSE>nul
:multiply
ECHO Type the first number you wish to multiply:
SET /P Nummul1=
ECHO Type the second number you want to multiply with the first number:
SET /P Nummul2=
ECHO.
SET /A Ans=%Nummul1%+%Nummul2%
ECHO The result is: %Ansmul%
ECHO.
ECHO Press any key to exit.
PAUSE>nul
:divide
ECHO Type the first number you wish to divide:
SET /P Numdiv1=
ECHO Type the second number you want to divide with the first number:
SET /P Numdiv2=
ECHO.
SET /A Ansdiv=%Numdiv1%+%Numdiv2%
ECHO The result is: %Ansdiv%
ECHO.
ECHO Press any key to exit.
PAUSE>nul
May I know what is the problem with this and the correct code?
There were too many issues to mention in the comment section so please take a look at this example against yours to see if you can identify them:
#ECHO OFF
TITLE Simple Calculator
SET /P "Selection=Enter + to Add, - to Subtract, * to Multiply or / to Divide: "
IF "%Selection%"=="+" GOTO Add
IF "%Selection%"=="-" GOTO Subtract
IF "%Selection%"=="*" GOTO Multiply
IF "%Selection%"=="/" GOTO Divide
GOTO :EOF
:Add
SET /P "Numadd1=Enter an addend: "
SET /P "Numadd2=Enter another addend: "
SET /A Ansadd=Numadd1+Numadd2
ECHO.
ECHO The sum is: %Ansadd%
ECHO.
PAUSE
GOTO :EOF
:Subtract
SET /P "Numsub1=Enter the minuend: "
SET /P "Numsub2=Enter the subtrahend: "
SET /A Ansub=Numsub1-Numsub2
ECHO.
ECHO The difference is: %Ansub%
ECHO.
PAUSE
GOTO :EOF
:Multiply
SET /P "Nummul1=Enter a factor:"
SET /P "Nummul2=Enter another factor: "
SET /A Ansmul=Nummul1*Nummul2
ECHO.
ECHO The product is: %Ansmul%
ECHO.
PAUSE
GOTO :EOF
:Divide
SET /P "Numdiv1=Enter the dividend: "
SET /P "Numdiv2=Enter the divisor: "
SET /A Ansdiv=Numdiv1/Numdiv2
ECHO.
ECHO The quotient is: %Ansdiv%
ECHO.
PAUSE
Ideally you should make sure that none of your variables have existing values at the start of the script and check that the entered values are compatible/validated before using them too!
Edit
You could probably make the code shorter too:
#ECHO OFF
TITLE Simple Calculator
FOR %%A IN (Operator Integer1 Integer2 Result) DO SET "%%A="
SET /P "Operator=Enter + to Add, - to Subtract, * to Multiply or / to Divide: "
IF DEFINED Operator (SET "Operator=%Operator:~,1%") ELSE GOTO :EOF
ECHO(%Operator%|FINDSTR /L "+ - * /">NUL||GOTO :EOF
SET /P "Integer1=Enter your starting integer: "
SET /P "Integer2=Now the other integer: "
SET /A Result=Integer1 %Operator% Integer2
ECHO(
ECHO The Answer is: %Result%
ECHO(
PAUSE
These two lines
ECHO if you want to add press 1,subtract 2,multiply 3 and divide 4
set /a selection =
should be:
set /p selection=if you want to add press 1,subtract 2,multiply 3 and divide 4:
There are a few errors in your code, including the math. Try and take a look at my code and compare it with yours.
#ECHO OFF
TITLE Simple Calculator
echo If you want to add press 1, subtract 2, multiply 3 and divide 4
set /p selection=
if "%selection%"=="1" goto add
if "%selection%"=="2" goto sub
if "%selection%"=="3" goto multiply
if "%selection%"=="4" goto divide
:add
ECHO Type the first number you wish to add:
SET /P Numadd1=
ECHO Type the second number you want to add to the first number:
SET /P Numadd2=
SET /A Ans=%Numadd1%+%Numadd2%
goto end
:sub
ECHO Type the first number you wish to subtract with:
SET /P Numsub1=
ECHO Type the second number you want to subtract from %Numsub1%:
SET /P Numsub2=
SET /A Ans=%Numsub1%-%Numsub2%
goto end
:multiply
ECHO Type the first number you wish to multiply:
SET /P Nummul1=
ECHO Type the second number you want to multiply with the first number:
SET /P Nummul2=
SET /A Ans=%Nummul1%*%Nummul2%
goto end
:divide
ECHO Type the first number you wish to divide:
SET /P Numdiv1=
ECHO Type the second number you want to divide with the first number:
SET /P Numdiv2=
SET /A Ans=%Numdiv1%/%Numdiv2%
:end
ECHO.
ECHO The result is: %Ans%
ECHO.
ECHO Press any key to exit.
PAUSE>nul
I know I can write an echo > C:/Folder/name.txt
But I have a generator to make 2 number for Cord and can't figure out a quick way to make a one line echo > with all the points
for shortness I'll simplify my code because the current code is not the issue
Echo off
Setlocal EnableDelayedExpansion
set R=1
set Number=1
:Loop
if %R% EQU 1 (set /p Max=How many Max Points? ) Else(
echo.)
set /p PX%number%=What is PointX%number%?
set /p PY%number%=What is PointY%number%?
if %Number% GEQ %Max% (goto :fin) Else(
set /a Number=%Number%+1 & set R=2 & Goto :loop)
This Is what Im trying to Optimize
:fin
echo (%PX1%,%PY1%),(%PX2%,%PY2%),(%PX3%,%PY3%) ... Ect >C:Folder/File.txt
Is there any way to make all the generated numbers on 1 line
Credit to Squashman for the Answer - Thank you!
Correct Code:
Echo off
Setlocal EnableDelayedExpansion
set R=1
set Number=1
set Line=Test
:Loop
if %R% EQU 1 (set /p Max=How many Max Points? ) Else (
echo.)
set /p PX%number%=What is PointX%number%?
set /p PY%number%=What is PointY%number%?
set line=%line%(!PX%number%!,!PY%number%!),
if %Number% GEQ %Max% (goto :fin) Else (
set /a Number=%Number%+1 & set R=2 & Goto :loop)
:fin
echo %Line:~0,-1% >C:Folder/File.txt
Credit to Squashman for the Answer - Thank you!
The logic is so much simpler if you get the max point count before the loop. And the FOR /L loop can auto increment your counter and eliminate the need for GOTO.
#echo off
setlocal enableDelayedExpansion
set /p "cnt=How many points? "
set "ln="
for /l %%N in (1 1 %cnt%) do (
echo(
set /p "PX%%N=What is PointX%%N? "
set /p "PY%%N=What is PointY%%N? "
set "ln=!ln!(!PX%%N!,!PY%%N!),"
)
echo(
echo !ln:~0,-1!
I have been having troubles with batch-codes that I would expect to work, but don't...
Below is what I have written...
#echo off
cls
:loop
set /p "input=Input a number: "
set /a "number=%input%" 2>nul
REM check if input valid
if "%input%" NEQ "%number%" (
cls
Echo Please Enter a valid number! &Echo.&Echo.
goto :loop
)
Set /a Even=number%%2
if %Even% EQU 0 (
Echo Substituting Even Number in: x / 2
Echo set /p"=(%number%) / 2 = "
set /a answer=number/2
) Else (
Echo Substituting Odd Number in: 3x - 1
<nul set /p"=3(%number%)-1 = "
set /a answer=number*3
set /a answer=answer-1
)
Echo %answer%
Echo.
Echo.
goto :loop
Echo Unexpected Error . . .
pause
Exit
Whenever I input a number into the console, it does the math, like I want it to, but prints the number -1, and every time i input another number, the number goes to -2, -3, -4, so on.
Put a setlocal enableextensions at the beginning after the #echo off, e.g.
#echo off
setlocal enableextensions
cls
Also, I think you would also need to use delayed variable expansion (usually denoted by !var!), which would change your script above to something like this:
#echo off
setlocal enableextensions enabledelayedexpansion
cls
:loop
set /p "input=Input a number: "
set /a number=!input! 2>nul
REM check if input valid
if "!input!" NEQ "!number!" (
cls
Echo Please Enter a valid number!
Echo.
Echo.
goto :loop
)
REM Make sure that it is an integer put in (just in case)
set /a int=!number! %% 1
if "!input!" NEQ "!int!" (
cls
Echo Please Enter a valid number!
Echo.
Echo.
goto :loop
)
Set /a Even=!number! %% 2
if !Even! EQU 0 (
Echo Substituting Even Number in: x / 2
set /a answer=!number! / 2
) Else (
Echo Substituting Odd Number in: 3x - 1
set /a answer=!number! * 3 - 1
)
Echo !answer!
Echo.
Echo.
goto :loop
I also would like to point out that I also fixed a few other bugs (set /p isn't of any use in this script at all, especially in where it is used, and also you need the modulus to find even/odd).
I have problem with "%_Link%%num%" its not working show up link after load from txt format. I think "%_Link%%num%" is wrong syntax function. but I know %_Link1%,%_Link2%,etc can work... but i want loop that will add/change number # in variable name like "_Link#" changeable number as #. here code below...
TEXT FORMAT (NOTEPAD):
http://www.google.com
http://www.nba.com
test3
test5
test6
test7
SCRIPT code:
#echo off
:: LOAD FILE
SetLocal EnableDelayedExpansion
Set n=
Set _InputFile=loadlink.txt
For /F "tokens=*" %%I IN (%_InputFile%) DO (
Set /a n+=1
set /a i = 1
Set _Link!n!=%%I
Set /a num = 2
)
:loop1
CLS
echo.
echo %_Link%%num%
echo %i% seconds
start "" /b "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" %_Link%%num%
set /a i = i - 1
set /a num = num + 1
pause
GOTO loop1
:: pause
Try this:
ECHO !_Link%n%!