0
$testCase="";
$strength="";
$i="";$j="";$sum=0;
$submit=$_POST['submit'];

if(!empty($submit))
{
    $testCase=$_POST['TestCase'];
    $strength=$_POST['strength'];
}
else
{ 
    die("Please enter the Number of <strong>test case</strong><br/> and <strong> Strength of audience</strong>");
}
while($testCase>0)
{
    for($i=1;$strength;$i=$i+1)
    {
        $user[$i]=$i+1;
    }

    //finding the total number of stickers

    for($j=1;$j<$strength;$j=$j+1)
    {
        $sum=$sum+$user[$j];
    }

}
echo "The total number of <strong>Stickers</strong> are = " . $sum;
cmbuckley
  • 40,217
  • 9
  • 77
  • 91
aps240
  • 21
  • 2

2 Answers2

1

Because you do this: while ($testCase > 0) { and do not decrase the $testCase ever. Also, it's better if you put your loops into your if condition.

And you do not need to create $strength variable. Try this:

$sum = 0;
if (!empty($_POST["submit"]) && !empty($_POST["testCase"]) && !empty($_POST["strength"])) {
    $testCase = $_POST["testCase"];
    while ($testCase > 0) {
        for ($i = 1; $i < $_POST["strength"];$i++) {
            $user[$i] = $i + 1;
        }
        for ($j = 1; $j < $_POST["strength"]; $j++) {
            $sum = $sum + $user[$j];
        }
        //Here you need to decrase testcase
        $testCase--;
    }

} else {
    die("Please enter the Number of <strong>test case</strong><br/> and <strong> Strength of audience</strong>");
}
echo "The total number of <strong>Stickers</strong> are = " . $sum;

NOTE: In PHP arrays are always started with 0, if you do not specify keys directly. Check your for loops for this.

vaso123
  • 12,347
  • 4
  • 34
  • 64
0

This line: for($i=1;$strength;$i=$i+1) should probably be: for($i=1;$i<$strength;$i=$i+1)

Chris
  • 1