Jump to content

kaveman50

Members
  • Posts

    60
  • Joined

  • Last visited

    Never

Everything posted by kaveman50

  1. Does anyone know how to do (or at least help me get started on) a binary search? I have to create a list of 25 names in alphebetical order. Create a binary search program that searches for an input name. Tell the user whether or not the name was found. The names i'll use will be. $arr=array('Allen', 'Brad', 'Chris', 'Drake', 'Eugene',' Frank', 'Greg', 'Hank', 'Ingrid', 'Jim', 'Kraig', 'Lee', 'Molly', 'Nathan', 'Otis', 'Peter', 'Quame', 'Rolland', 'Sean', 'Tiffany', 'Utopia', 'Venus', 'Walley', 'Xephinorgi', 'Yullanda', 'Zeus');
  2. I'm probably really off. It's just coming up blank. I guess I should just start over...
  3. ?? This is what I have so far. I'm not sure where to go from here though. <? $grades=array(); $file=fopen("grades.txt","r") or exit("Unable to open file!"); $file=fopen("HIGHER.txt","r") or exit("Unable to open file!"); $file=fopen("LOWER.txt","r") or exit("Unable to open file!"); while(!feof($file)) { $f = fgets($file); array_push($grades, $f); } $arr[$i] = explode('", ', $grades[$i]); fclose($file); ?>
  4. How could I have a main text file, for instance PRIMARY.txt that has scores of certain tests, but then make 2 more txt files using php that'll make it so that it'll show scores lower than 50 in a file called lower.txt and the scores greater than 50 in a file called higher.txt? Anyone know?
  5. Thanks! The splice worked. I'm not sure why the shift wasn't working. Anyways, no more questions on this program again I promise.
  6. Sorry I meant dropping the 2 lowest scores.
  7. It just displays the average without it rounded off, though.
  8. Oh yeah how would I drop the 2 lowest scores?
  9. Oh I didn't see the array POST you added in the second time. My bad. Thanks for the help.
  10. I'm sorry but I still don't really get what you mine by putting a blank [] after the num. I tried it once and it gave me even more errors. The most recent code I have doesn't say any errors when I click submit, but it returns zero. <form method='post' action=''> Enter Student's Name: <br/> <input type="text" name="num1" value = " " /> <br/> <br/> Enter Seven Tests Scores Here: <br/><input type="text" name="num1" value = "<?=$_POST['num']?>" /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?>" /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?>" /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?>" /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?>" /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?>" /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?>" /> <br/><input type='Submit' name='Submit' value="Submit" /> </form> <? $arr=array($_POST['num']); function getAverage($arr) { asort($arr); array_shift($arr); array_shift($arr); return array_sum($arr) / count($arr); } if(isset($_POST['Submit'])) { echo array_sum($arr) / count($arr); } ?>
  11. For some reason it still gives me all those warnings. The only difference now is that it appears after you press submit. Do I also need to do the <?=$=......?> for the value of my submit button?
  12. Oh wait it's saying Warning: asort() expects parameter 1 to be array, null given in /Applications/XAMPP/xamppfiles/htdocs/webalizer/av.php on line 25 Warning: array_shift() expects parameter 1 to be array, null given in /Applications/XAMPP/xamppfiles/htdocs/webalizer/av.php on line 25 Warning: array_shift() expects parameter 1 to be array, null given in /Applications/XAMPP/xamppfiles/htdocs/webalizer/av.php on line 25 Warning: array_sum() expects parameter 1 to be array, null given in /Applications/XAMPP/xamppfiles/htdocs/webalizer/av.php on line 26 Warning: Division by zero in /Applications/XAMPP/xamppfiles/htdocs/webalizer/av.php on line 26 <form method='post' action=''> Enter Student's Name: <br/> <input type="text" name="num1" value = " " /> <br/> <br/> Enter Seven Tests Scores Here: <br/><input type="text" name="num1" value = "<?=$_POST['num']?> " /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?> " /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?> " /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?> " /> <br/><input type="text" name="num1" value = " <?=$_POST['num']?>" /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?> " /> <br/><input type="text" name="num1" value = "<?=$_POST['num']?> " /> <br/><input type='Submit' name='Submit' value="Submit" /> </form> <? $arr=array($_POST['num']); function getAverage($arr) { asort($arr); array_shift($arr); array_shift($arr); return array_sum($arr) / count($arr); } echo getAverage($_POST['num']); ?>[/Code]
  13. and then would i just do print_r($counter) and leave my posts the way they are after i add in your code?
  14. does anyone know how to make it so that you can make user input 7 grades and ouput average and drop the 2 lowest scores? This is all i know how to do <form method='post' action=''> Enter Student's Name: <br/> <input type="text" name="num1" value = " " /> <br/> <br/> Enter Seven Tests Scores Here: <br/><input type="text" name="num1" value = "<?=$_POST['Steve']?> " /> <br/><input type="text" name="num1" value = "<?=$_POST['Steve']?> " /> <br/><input type="text" name="num1" value = "<?=$_POST['Steve']?> " /> <br/><input type="text" name="num1" value = "<?=$_POST['Steve']?> " /> <br/><input type="text" name="num1" value = " <?=$_POST['Steve']?>" /> <br/><input type="text" name="num1" value = "<?=$_POST['Steve']?> " /> <br/><input type="text" name="num1" value = " " /> <br/><input type='Submit' name='Submit' value="Submit" /> </form> <? $steve1=$_POST['Steve']; $a=array($_POST['Steve']); print_r (array_sum($a)) ; ?>
  15. Nah it's not homework but I figured it out. Thanks guys
  16. It can't have names already in the code because the user has to enter the names.
  17. Hello does anyone know how to solve this? Accept 5 words to be input in alphabetical order and store them in an array (If input out of alphabetical order, write your script to fix it). Then accept a 6th word as input and store it in the array in its correct alphabetical position.
  18. Mikesta or anyone else know what to do?
×
×
  • 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.