Batch File "Unbalanced Parenthesis"
<p>So I have this program I'm trying to make:</p>

<pre><code>//@echo off
@title Calculate Caloric Needs
set /p name=What is the name of the individual in question? 
CLS

:START
set /p sex=Is %name% a M(ale) or F(emale)? (M/F) 
CLS
if NOT %sex%==M if NOT %sex%==F ( 
    echo Invalid Selection...Try Again....
    goto START
)

set /p w=What is the target weight of %name%? 
CLS

set /p h=What is the height of %name% IN INCHES? 
CLS

set /p a=What is the age of %name%? 
CLS

if %sex%==M set /a result=66 + (6.23 * %w%) + (12.7 * %h%) - (6.8 * %a%)
if %sex%==F set /a result=655+(4.35*%w%)+(4.7*%h%)-(4.7*%a%)

echo %result% is the caloric intake for %name%.
pause
exit
</code></pre>

<p><em><code>@echo off</code> has been disabled for the sake of troubleshooting.</em></p>

<p>It's a simple program meant to do some caloric intake calculations that are a bit arduous to do one by one.</p>

<p>Every time I reach the point where I need to do arithmetic calculations one of two things happens:</p>

<ol>
<li>if I wrap the <code>set /a</code> statement in an <code>if %sex%==M ( CODE HERE )</code> block, the program will exit unexpectedly without showing an error message.</li>
<li>If I don't and have it all on one line (as it is in the example code posted above) then I get the message <code>Unbalanced Parenthesis</code> without any further explanation (thanks Windows...).</li>
</ol>

<p>As far as I know, mathematically speaking the parenthesis are completely balanced.</p>

<p>I've tried:</p>

<ul>
<li>wrapping the <code>set /a</code> statement in both <code>""</code> and <code>[]</code>, <code>set /a "result=66 + (6.23 * %w%) + (12.7 * %h%) - (6.8 * %a%)"</code> or <code>set /a [result=66 + (6.23 * %w%) + (12.7 * %h%) - (6.8 * %a%)]</code></li>
<li>escaping some or all of the parenthesis used in the arithmetic <code>set /a result=66 + ^(6.23 * %w%^) + ^(12.7 * %h%^) - ^(6.8 * %a%^)</code></li>
<li>reducing the amount of parenthesis for the sake of testing <code>set /a result=66 + (6.23 * %w%)</code>. <em>If I use <code>set /a result=66 + (6.23 * %w%)</code> exactly, I can actually wrap the statement in an <code>if ( CODE HERE )</code> block and have it actually return an error value. Although the error is still <code>Unbalanced Parenthesis</code>...</em></li>
<li>lengthening or shortening the number of spaces in the arithmetic itself <code>set /a result=66+(6.23*%w%)+(12.7*%h%)-(6.8*%a%)</code> VS. <code>set /a result=66 + (6.23 * %w%) + (12.7 * %h%) - (6.8 * %a%)</code></li>
<li>all combinations of the above</li>
</ul>

<p>So I am at a loss as to what could be causing this bizarre behavior.</p>