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" ;

?>

Recommended Answers

All 3 Replies

Member Avatar for diafol

Is this homework??

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

Member Avatar for diafol

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.