Jump to content

[SOLVED] $end error


doucettej3

Recommended Posts

Hey im new at php..i just started my programmin class in college and i keep getting a $end error in my lab. any suggestions would be nice. 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;
}
?>

Link to comment
Share on other sites

$end error means you have a bracket that's left open.

 

The { bracket at the beginning after you use <?php is not needed and is causing the problem from what I can tell, although I'm not sure what the whole switch() thing is about.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.