Question: I'm working on some php code and I'm stuck on how to fix it. The first for loop keep repeating and I don't know how
I'm working on some php code and I'm stuck on how to fix it.
$Numbers= array(20);
$Mean=0;
//these functions are called
getNumbers();
calMean();
NumbersaboveMean();
calMedian();
calMode();
Mode();
//this function gets the numbers from the user
function getNumbers()
{
$temp=0;
echo " Enter up to 10 float point numbers ";
for( $n=0; $n<20; $n++)
{
$Number[$n]=(float)readline('Enter a number: ');//gets the number from the user
}
//This arranges the numbers in order from least to greatest
for( $n=0; $n<20; $n++)
{
$temp=$Number[$n];
$Number[$n]=$Number[$n+1];
$Number[$n+1]=$temp;
}
}
//This function calculates the mean
function calMean()
{
for( $n=0; $n<20; $n++)
{
$sum=$sum+$Number[$n];
}
$Mean=$sum/(20);
echo "The mean of your numbers is " + $Mean;
}
// funciton determines how many numbers are above the mean
function NumbersaboveMean()
{
$track=0;
for($n=0;$n<20;$n++)
{
if($Number[$n]>$Mean)
{
$track++;
}
}
echo " There are " + $track + " numbers above the mean.";
}
//determines what the median is
function calMedian()
{
$median=Number[10];
echo "The median of your numbers is " + $median;
}
//this function determines what the mode is
function calMode()
{
$mode=0;
$count=0;
$count2=0;
$md2=0;
for($n=0;$n<18;$n++)
{
if($Number[$n]===$Number[$n+1])
{
$count2++;
}
if(count==count2)
{
$count=$count2;
$count2=0;
$md2=1;
}
else if(count
{
$mode=$Number[$n];
$count=$count2;
$count2=0;
}
}
}
//determines if there is 1 mode or more
function mode()
{
if(md2>0)
{
echo "There is more than 1 mode.";
}
else
{
echo "The mode is " + mode;
}
}
?>
The first for loop keep repeating and I don't know how to proceed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
