Not sure how to fix error

Got an error, can't figure out what i did wrong

Page 1 of 1

3 Replies - 599 Views - Last Post: 26 October 2009 - 08:53 AM Rate Topic: -----

#1 dragonseyeangie  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 41
  • Joined: 20-October 08

Not sure how to fix error

Post icon  Posted 26 October 2009 - 08:40 AM

Here's the error I got

Parse error: syntax error, unexpected T_INC, expecting ')' in C:\xampp\htdocs\ShortForm3.php on line 9

and here's the code

<?php 
	// Create an array
	$numbers = array();
	
	// The generate_numbers function generates a number from 1 to 1000
	// and puts it into an array fifty times
	function generate_numbers($numbers) {
		
		for ($i = 0; $i <= 50; i++) {
			$numbers[$i] = rand(1, 1000);
		}
		
	}
	
	// The count_numbers function counts the number of elements in the array
	function count_numbers($numbers) {
		
		$size = count($numbers, $count_recursive);
		
		return $size;
	
	}
	
	// The sum_numbers function sums the number of elements in the array
	function sum_numbers($numbers) {
	
		for ($i = 0; $i <= $size; i++)
		{
			$sum += $numbers[i];
		}
		
		return $sum;
	}
	
	// The calculate_median function calculates the median of the array
	function calculate_median($numbers) {
	
			$h = intval($size / 2);
			
			if ($size % 2 == 0)
			{
				$median = ($numbers[$h] + $numbers[$h - 1]) / 2;
			}
			else {
				$median = $numbers[$h];
			}
			
			return $median;
	}
	
	// The highest_values function determines the five highest values in the array
	function highest_values($numbers) {
	
		$newnumbers = array_unique($numbers);
		
		sort($newnumbers);
		$reversenum = array_reverse($newnumbers);
		
		$highest = array();
		
		for ($i = 0; $i <= 5; $i++) {
			
			$highest[$i] = $reversenum[$i];
		
		}
		
		return $highest;
	}
	
	// The lowest_values function determines the five lowest values in the array
	function lowest_values($numbers) {
	
		$newnumbers = array_unique($numbers);
		sort($newnumbers);
		$lowest = array();
		
		for ($i = 0; $i <= 5; $i++) {
		
			$lowest[$i] = $newnumbers[$i];
			
		}
		
		return $lowest;
	}
	
	// The calculate_range function calculates the range of the array
	function calculate_range($numbers) {
	
		sort($numbers);
		
		$range = $numbers[49] - $numbers[0];
		
		return $range;
	}
	
	// The determine_mode function determines the mode of the array
	function determine_mode($numbers) {
	
		$counts = array_count_values($numbers);
		sort($counts);
		
		$valcount = count($counts);
		$num = $counts[$valcount];
		$flipped = array_flip($counts);
		$mode = $flipped[$num];
		
		return $mode;
		
	}
	
	echo "<pre>";
	echo "<p>The number of elements in the array are: ", count_numbers();
	echo "<p>The sum of the array elements is: ", sum_numbers();
	echo "<p>The median is: ", calculate_median();
	echo "<p>The range is: ", calculate_range();
	echo "<p>The mode is: ", determine_mode();
	echo "<p>The five highest values are: ", highest_values();
	echo "<p>The five lowest values are: ", lowest_values();
	
?>



heres the section it's saying i have an error in

// The generate_numbers function generates a number from 1 to 1000
	// and puts it into an array fifty times
	function generate_numbers($numbers) {
		
		for ($i = 0; $i <= 50; i++) {
			$numbers[$i] = rand(1, 1000);
		}
		
	}



i feel so dumb having to ask but just glancing at it i can't see what's wrong.

Is This A Good Question/Topic? 0
  • +

Replies To: Not sure how to fix error

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Not sure how to fix error

Posted 26 October 2009 - 08:48 AM

I do believe the error is in this line

for ($i = 0; $i <= 50; i++) {



That line should look like

for ($i = 0; $i <= 50; $i++) {



You forgot the $ in i++
Was This Post Helpful? 0
  • +
  • -

#3 dragonseyeangie  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 41
  • Joined: 20-October 08

Re: Not sure how to fix error

Posted 26 October 2009 - 08:51 AM

View PostPsychoCoder, on 26 Oct, 2009 - 07:48 AM, said:

I do believe the error is in this line

for ($i = 0; $i <= 50; i++) {



That line should look like

for ($i = 0; $i <= 50; $i++) {



You forgot the $ in i++


i feel like a complete dumbass now, thanks
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Not sure how to fix error

Posted 26 October 2009 - 08:53 AM

Don't feel like a dumb ass, it happens all the time, even to people who have been doing this for years and years. Glad I could help.

Now go forth and become a Looping Ninja and show the world :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1