Claire_Ann Posted November 21, 2013 Share Posted November 21, 2013 HERE IS MY CODE: _____________ Machine1.html _____________ <!DOCTYPE> <html> <head> </head> <body> <form method="get" action="MachineTemplate.php"> Enter a NUM1:<input type="text" name="num1" value=""> Enter a NUM2:<input type="text" name="num2" value=""> <input type="submit" name="submit" value="Submit"> </form> </body> </html> __________________ MachineTemplate.php __________________ <!DOCTYPE> <html> <head> <title>MACHINE TEMPLATE</title> </head> <body> <h2>Middle Squared</h2> <?php $a =$_REQUEST ['num1']; $b =$_REQUEST ['num2']; for ($i=$a+1; $i < $b; $i++) { $squared = $i * $i; echo ($i . "=" . $squared . "<br>"); } ?> </body> </html> and this is the output: Middle Squared2=43=94=165=256=367=498=649=81 But I can't get the sum of all the squared. Can you help me? Anyone? Thanks so Much! Link to comment https://forums.phpfreaks.com/topic/284131-im-creating-a-program-that-prompts-the-user-for-2-different-positive-integers-then-prints-out-the-numbers-between-the-2-integers-inclusive-and-the/ Share on other sites More sharing options...
Ch0cu3r Posted November 21, 2013 Share Posted November 21, 2013 You posted this in the wrong forum section. Should be PHP Coding Help. But I'll answer. First before the for loop add this $total = 0;Then in your for loop add $squared to the $total variable $total += $squared; Then after your loop you can echo $total to see sum of all the square numbers. Complete for loop code $total = 0; for ($i=$a+1; $i < $b; $i++) { $squared = $i * $i; echo ($i . "=" . $squared . "<br>"); $total += $squared; // add square number to $total } echo "Total: $total"; Link to comment https://forums.phpfreaks.com/topic/284131-im-creating-a-program-that-prompts-the-user-for-2-different-positive-integers-then-prints-out-the-numbers-between-the-2-integers-inclusive-and-the/#findComment-1459342 Share on other sites More sharing options...
cyberRobot Posted November 21, 2013 Share Posted November 21, 2013 Moving to PHP Coding Help section. Link to comment https://forums.phpfreaks.com/topic/284131-im-creating-a-program-that-prompts-the-user-for-2-different-positive-integers-then-prints-out-the-numbers-between-the-2-integers-inclusive-and-the/#findComment-1459354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.