English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Also, how can I create an algorithm that describes the operation of a light that can be turned on or off using either of two switches?

All help is appreciated. Thanks. :D

2007-02-17 15:32:22 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

Here's some code that figures the mean and median for a series of numbers stored in an array:

$mynumbers = new Array();
$len = array_length($mynumbers);
$mid = floor($len / 2);
foreach($mynumbers as $num) {
$total += $num;
}
$mean = $total / $len;
$median = $mynumbers[$mid];

Here's some JavaScript that describes the interoption of two single-pole, single-throw switches connected in series. False is off, true is on:

var switch1 = true;
var switch2 = true;

function toggleSwitch(switchID) {
switchID = !switchID // reverse global setting of switch
}

function circuitStatus() {
if($switch1 == true && $switch2 == true) {
alert('Circuit open!');
}
else {
alert('Circuit closed!');
}
}

Toggle Switch 1

Toggle Switch 2

2007-02-17 15:51:52 · answer #1 · answered by Anonymous · 1 0

First, have a running COUNT of numbers entered.
Second, have a running SUM of numbers entered.
At any time, average = SUM / COUNT.

Oh, and the light switch is an Exclusive OR function.
Light = Sw1 XOR Sw2

2007-02-17 16:32:20 · answer #2 · answered by Alan 6 · 0 0

fedest.com, questions and answers