Jump to content

[SOLVED] output error


doucettej3

Recommended Posts

im trying to make the program output the result from one of my functions and it leaves out the result in the output. so it says the sum of 1-x is blank. heres the code:

<?php
{
$action = $_POST['action'];
$even_max = $_POST['even_max'];
$odd_max = $_POST['odd_max'];
$variable1 = $_POST['variable1'];
$variable2 = $_POST['variable2'];


function sum_even($even_m)
{
  $count = 0;
  while($even_max > $count)
    {
    $count = $count + 2;
    $sum = $sum + $count;
   }
  return $sum;
}

function sum_odd($odd_m)
{
  $count = 1;
  while($odd_max > $count)
    {
    $count = $count + 2;
    $sum = $sum + $count;
   }
  return $sum;
}

function exponent($variable1, $variable2)
{ 
   $count = 0;
   while ($count < $variable2)
{
$count= $count + 1;
$answer = $variable1 * $variable1;
   }
  return $answer;
}

switch($action)
{
  case 'even':	
    
$even_max = $_POST['even_max'];
    $result = sum_even($even_m);
    echo "The sum of all the numbers between 1-$even_max is $result";
break;
}
}
?>

 

EDIT: Please use the code tags (


) when posting code

Link to comment
https://forums.phpfreaks.com/topic/128391-solved-output-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.