954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Multiple looping through Array to find average

Hi everyone!
This problem has me stumped. I haven't had to work with php for about a year and I have sure gotten rusty. I have created my array, but beyond that was just doodling ideas to try and put something together...can you offer advice?

Here is the problem I was given:
A hypothetical program computes for three seconds then outputs a variable length record to be printed. The printer takes from 0.75 to 4.75 seconds (average time is 2.75 seconds) to print each output record. (Use a random number generator)
The hypothetical program loops 500 times for each case of software buffers (0, 1, 2, 3, 4, 5, 10, 25, and 100 software output buffers). Calculate the AVERAGE time for the program to “virtually compute and print” a record from the 500 records, for EACH of the 9 choices of buffer. Plot the results (by hand is OK). The Y axis is from zero to 8 seconds, and the X axis is nonlinear and displays all nine cases of buffers.

Here is my work so far:

<?php
//create an array of the 9 buffers
$buffer['0'] = "Buffer 0";
$buffer['1'] = "Buffer 1";
$buffer['2'] = "Buffer 2";
$buffer['3'] = "Buffer 3";
$buffer['4'] = "Buffer 4";
$buffer['5'] = "Buffer 5";
$buffer['10'] = "Buffer 10";
$buffer['25'] = "Buffer 25";
$buffer['100'] = "Buffer 100";

//Calculate the AVERAGE time for the program to “virtually compute and print” a record from the 500 records, for EACH of the 9 choices of buffer
for ($i = 1; $i < 500; $i++) {
	$average=rand(.75, 4.75)+3 
}
 
//Calculate the AVERAGE time for the program to “virtually compute and print” a record from the 500 records, for EACH of the 9 choices of buffer

//output the result
  echo $buffer, "took", $average, "seconds" ;

?>
kkasp
Newbie Poster
8 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

Is this homework??

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Anyone out there able to take a look at this code and tell me if I am on the right path or offer advice?

kkasp
Newbie Poster
8 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

We're waiting for you to tell us whether it's homework or not...

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: