unable to get correct output for dose calculator with bat scripts

Viewed 32

I created a simple batch code to calculate a dose of medication. For a child of 8kg and a dose of 15mg/kg. I should get an amount of 5ml with this formula

amount = ((weight * dose) / 120) * 5

but im getting missing operant, echo is off

can someone please direct me?

here are my codes.

@echo off
title paracetamol dose calculator
color 5a
:loop
set /p weight of the child = weight
set /p dose of paracetamol = mgperkg
goto A
:A
set/a result=(%weight%*%dose%)/120)*5
echo %result%
pause
gotoloop
1 Answers

There are some things that have to be fixed.

As Jeff pointed out, you are using SET incorrectly. The variable comes first, then equals (without spaces apparently) then the text.

set /P weight=Weight of the child:

set /P mgperkg=Dose of paracetamol:

The calculation has to be slightly modified because we are calculating integers. This means for weithg = 10 and mgperkg equals 20 we would have "(200/120)5", which is actually "15" So wee need to push the "*5" into the parenthesis.

set /a result=((%weight%*%mgperkg%*5)/120)

And lastly (from what I can tell) the gotoloop is lacking a space

goto loop

Related