达到均值、中值和众数时 PHP 崩溃

问题描述

我和我的团队正在撰写一篇关于 Pascal 和 PHP 的研究论文,最后一步我们必须编写一个简单的程序,将浮点数计算为均值、中值和众数。但是,该程序拒绝在我合作伙伴的 NetBeans PHP IDE 和我的 Visual Basic 上运行。

<?PHP
        
        $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<count2)
           {
               $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;
         }
         
        }
     
        ?>

当我运行它时,在它崩溃之前我得到了大约 10 个以上的输入数字循环,“代码以 -1 (FFFFFF~~~) 退出(当我把我的电脑放回原位时我会更新它几个小时。

老实说,我们真的不需要修复不运行的问题,我们只是想知道代码是否运行我们也想要它。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)