rohitb Posted August 22, 2013 Share Posted August 22, 2013 (edited) what is wrong with this code of mine. i am getting warning messages Warning: Division by zero in /home/rohitb/public_html/test/live nifty trend/trend.php on line 52 Warning: Division by zero in /home/rohitb/public_html/test/live nifty trend/trend.php on line 54 <Form name ="form1" Method ="POST" > Enter Nifty Spot Price<INPUT TYPE = "TEXT" value="<?php echo $_POST['spotprice'] ?>" Name ="spotprice"/> <INPUT TYPE = "Submit" Name = "getCallPut" VALUE = "Next->"> </form> <?php if(isset($_POST['getCallPut'])) { callput(); } function callput() { $spotPrice = 1.0 * $_POST['spotprice']; if($spotPrice%100>=0 && $spotPrice%100<40){ $callStrikePrice=floor($spotPrice/100)*100 + 100; $putStrikePrice=floor($spotPrice/100)*100 - 100; }else if($spotPrice%100 >=40 && $spotPrice%100<=60){ $callStrikePrice=floor($spotPrice/100)*100 + 100; $putStrikePrice=floor($spotPrice/100)*100; }else{ $callStrikePrice=floor($spotPrice/100)*100 + 200; $putStrikePrice=floor($spotPrice/100)*100; } echo' <Form name ="form2" Method ="POST" >'; echo'Enter price for Nifty <input type="text" name="something" disabled="" style="border:none;width:40px;background-color:#000000;color:yellow;font-weight:bold;text-align:center" value="'.$callStrikePrice.'"/> CE <input type="text" name="callRate" size="10"><br><br>'; echo'Enter price for Nifty <input type="text" name="something1" disabled="" style="border:none;width:40px;background-color:#000000;color:yellow;font-weight:bold;text-align:center" value="'.$putStrikePrice.'"/> PE <input type="text" name="putRate" size="10">'; echo'<INPUT TYPE = "Submit" Name = "trend" VALUE = "Calculate Trend->">'; echo'</form>'; } ?> <?php if(isset($_POST['trend'])) { trend(); } function trend(){ $callRate = 1.0 * $_POST['callRate']; $putRate = 1.0 * $_POST['putRate']; $actualCallRate = ceil(100*(((($callStrikePrice-$spotPrice)-($callStrikePrice-($callStrikePrice+$putStrikePrice)/2))/($callStrikePrice - $spotPrice)) + 1) * $callRate); $actualPutRate = ceil(100.0 * (1 - (((($callStrikePrice+$putStrikePrice)/2.0 - $putStrikePrice) - ($spotPrice - $putStrikePrice))/($spotPrice - $putStrikePrice))) * $putRate); $buyPercent = ceil(10000.0 * $actualCallRate/($actualCallRate + $actualPutRate)); $sellPercent = ceil(10000.0 * $actualPutRate/($actualCallRate + $actualPutRate)); echo'The chances of Nifty Future going up is ' .$buyPercent/100.0. ' % and going down is ' .$sellPercent/100.0. ' %'; if($buyPercent==$sellPercent){ echo"<br/><h1 style='color:yellow'>TREND IS NEUTRAL</h1>"; }else if($buyPercent>$sellPercent){ echo"<br/><h1 style='color:green'>TREND IS UP</h1>"; }else{ echo"<br/><h1 style='color:red'>TREND IS DOWN</h1>"; } } ?> pls help me ...im trying to get some thing like this http://stocknews72.blogspot.in/p/stock-tips.html... how can i achieve this with above code Edited August 22, 2013 by rohitb Quote Link to comment https://forums.phpfreaks.com/topic/281460-what-is-wrong-with-this-code-of-mine/ Share on other sites More sharing options...
requinix Posted August 22, 2013 Share Posted August 22, 2013 (edited) Variables defined outside a function (including in a different function) are not available inside the function. So trend() cannot use $callStrikePrice or $spotPrice or $putStrikePrice or any of the other variables that callput() defines. Your script doesn't need those two functions. Put their code inline. Edited August 22, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/281460-what-is-wrong-with-this-code-of-mine/#findComment-1446253 Share on other sites More sharing options...
rohitb Posted August 22, 2013 Author Share Posted August 22, 2013 Variables defined outside a function (including in a different function) are not available inside the function. So trend() cannot use $callStrikePrice or $spotPrice or $putStrikePrice or any of the other variables that callput() defines. Your script doesn't need those two functions. Put their code inline. can u help me with that Quote Link to comment https://forums.phpfreaks.com/topic/281460-what-is-wrong-with-this-code-of-mine/#findComment-1446292 Share on other sites More sharing options...
requinix Posted August 22, 2013 Share Posted August 22, 2013 Put the code you have for the functions in the place where you were calling the functions. Give it a shot and post your code if it's not working. Quote Link to comment https://forums.phpfreaks.com/topic/281460-what-is-wrong-with-this-code-of-mine/#findComment-1446378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.