Jump to content

kylew

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Everything posted by kylew

  1. Thanks a bunch, I would never have thought of that, but an easy way to eliminate roundoff error. It certainly did the trick.
  2. Could you include some code? There are a few reasons why that error would appear, and seeing the code may make it easier to diagnose.
  3. I'm authoring a site that tests students on basic math. It tests everything from simple addition to decimals to fractions. I have a MySQL db that stores all information. I'm working on a couple of the specific tests right now, and am having serious trouble with roundoff error. For multiplying decimals, I've had to round to ten decimal places to remove extraneous bits that are messing up the grading of the quizzes. I'm working on division right now, and every once in a while, I'll get a division question that doesn't accept the correct answer as being correct. I have the data type for the questions in the db as FLOAT, and randomly generate decimals to store in the database. When the student proceeds to click "Grade Sheet", the code runs though the questions, calculates the correct answers, compares to the inputted answers, and scores the sheet. Somewhere in that comparison enlies the issue. [code]                 $additive1[$count]=$fields[$count2];         $additive2[$count]=$fields[$count2+1];         if($values[$count]==($additive2[$count]/$additive1[$count]))         {             $correct[$count]=true;             $numcorrect++;         }         else         {             $correct[$count]=false;         } [/code] This code checks to see if the entered value in $values[$count] (retrieved from $_POST[]) is equal to the correct answer. I've outputted the values and visually checked that the value the script is calculating and the value that is inputted match. There is some error in roundoff, because I rounded the decimal multiplication test and everything works well now, but there has to be some other error. The error might be where I generate random numbers with decimals. This is the fuction I use: [code] function random_0_1($min,$max) {     $rand=mt_rand($min,$max);     $decimal=((float)mt_rand()/(float)mt_getrandmax());     while($decimal<.05 || $decimal>.95)     {         $decimal=((float)mt_rand()/(float)mt_getrandmax());     }     $output=$rand+$decimal;     return $output; } [/code] Is there any particular way that I should initialize arrays used to store question values and answers to make them float friendly? I've been coding PHP for a while, but I'm still not very good at it. If you need any further information (which is entirely likely), let me know. I have not included a ton of the script, first because it is messy and poorly written, and second because this particluar script is over 750 lines long. Thank you in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.