Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

COULD SOMEBODY HELP ME FIX THE CODE? The code is below: the first function need

ID: 3553316 • Letter: C

Question

COULD SOMEBODY HELP ME FIX THE CODE? The code is below:

the first function need a variable equal the added values, then return that variable. Make each student a variable (student) that changes before each call

the math function, return array ($add,$sub, etc. and then echo the appropiate pocket [0],[1], etc.

something wrong in: list($add,$sub,$mul)=$result; it did not run the function!

THIS IS THE PROBLEM:

1.    Create a file named: Functions2.php in your text editor.



2.    Create a function (score) with five arguments that will add five values and return the result of that addition. Then echo five fictional students ($student) and give them each a score by calling the function with five random two-digit numbers for each student. Obviously the variable $student will have to change after each function run and each function run should have different numbers.

3.    Create a function (math) with two arguments that will do three things: 1) add two values; 2) subtract two values; 3) multiply two values, and then return each of those results in an array. You will now display the results in two different ways: 1) call the function into a variable and display each of the three array pockets with labels; 2) use the PHP list function to give a variable name to each array pocket, then display each of the three variables with labels. Use different values in each of the two function calls.

4.    Here is a sample of what your output should look like.

Brandon James:
Your Score = 242

Bugs Bunny:
Your Score = 278

Homer Simpson:
Your Score = 217

James T. Kirk:
Your Score = 254

Walter White:
Your Score = 202

==============

Add: 37
Subtract: 23
Multiply: 210

Add: 26
Subtract: 18
Multiply: 88

THIS IS THE CODE:


<?


function score($x1,$x2,$x3,$x4,$x5){


return $x1+$x2+$x3+$x4+$x5;


}


echo "Witch Hillary:<br/>Your Score = ", score(1,2,3,4,5);echo "<br/>";

echo "<br/>";

echo "Pinochio Bush:<br/>Your Score = ", score(11,21,31,41,51);echo "<br/>";

echo "<br/>";

echo "Helicopter Ben:<br/>Your Score = ", score(12,22,32,42,52);echo "<br/>";

echo"<br/>";

echo "Womenizer Clinton:<br/>Your Score = ", score(13,23,33,43,53);echo "<br/>";

echo"<br/>";

echo "Traitor Obama:<br/>Your Score = ", score(14,24,34,44,54);echo "<br/>";

echo "<br/>";


function math($x,$y){


$add = $x+$y;

$sub = $x-$y;

$mul = $x*$y;

$arr = array("add"=>$add, "subtract"=>$sub, "multiply"=>$mul);


return $arr;


}


$result = math(12,23);


echo "add: ", $result["add"], "<br/>";

echo "Subtract: ", $result["subtract"], "<br/>";

echo "Multiply: ", $result["multiply"], "<br/>";


list($add,$sub,$mul) = $result;


echo "add: ", $add, "<br/>";

echo "Subtract: ", $sub, "<br/>";

echo "Multiply: ", $mul, "<br/>";



Explanation / Answer

Try this :

<?php


function score($x1,$x2,$x3,$x4,$x5){


return $x1+$x2+$x3+$x4+$x5;


}


echo "Witch Hillary:<br/>Your Score = ", score(1,2,3,4,5);echo "<br/>";

echo "<br/>";

echo "Pinochio Bush:<br/>Your Score = ", score(11,21,31,41,51);echo "<br/>";

echo "<br/>";

echo "Helicopter Ben:<br/>Your Score = ", score(12,22,32,42,52);echo "<br/>";

echo"<br/>";

echo "Womenizer Clinton:<br/>Your Score = ", score(13,23,33,43,53);echo "<br/>";

echo"<br/>";

echo "Traitor Obama:<br/>Your Score = ", score(14,24,34,44,54);echo "<br/>";

echo "<br/>";


function math($x,$y){


$add = $x+$y;

$sub = $x-$y;

$mul = $x*$y;

$arr = array($add,$sub, $mul);


return $arr;


}


$result = math(12,23);


echo "add: ", $result[0], "<br/>";

echo "Subtract: ", $result[1], "<br/>";

echo "Multiply: ", $result[2], "<br/>";


list($add,$sub,$mul) = $result;


echo "add: ", $add, "<br/>";

echo "Subtract: ", $sub, "<br/>";

echo "Multiply: ", $mul, "<br/>";

?>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote