0

Ok i am trying to create a simple program that will allow me to use an array with 8 numbers, the output form should show the numbers in their original order that the user inputs them, in numerical order, Highest number, lowest number and then the average number. If anyone could help me it would be much appreciated. here's waht i have so far.

<?php
if (isset($_POST['numbers']))
//if (is_numeric($_POST['numbers']))
//if (!empty($_POST['numbers'])) 
{ 
    $Numbers = $_POST['numbers'];
	$big = max($Numbers);  
	$small = min($Numbers);
	$average = array_sum($Numbers) / count($Numbers);
	print "Original Sequence:<br>";

	$sorted = sort($Numbers);	
 	print "Sorted Numbers: $sorted";
	echo implode(" ",$Numbers);
	print "<br>Largest Number: $big<br>";
	print "Smallest Number: $small<br>";
	print "Average Number: $average<br>";}
else {
	print "<font color='red'>Invalid Input Grades must be Numeric</font>";}
		
	 
	?>
3
Contributors
13
Replies
14
Views
5 Years
Discussion Span
Last Post by Stefano Mtangoo
1

Ok i am trying to create a simple program that will allow me to use an array with 8 numbers, the output form should show the numbers in their original order that the user inputs them, in numerical order, Highest number, lowest number and then the average number. If anyone could help me it would be much appreciated. here's waht i have so far.

<?php
if (isset($_POST['numbers']))
//if (is_numeric($_POST['numbers']))
//if (!empty($_POST['numbers'])) 
{ 
    $Numbers = $_POST['numbers'];
	$big = max($Numbers);  
	$small = min($Numbers);
	$average = array_sum($Numbers) / count($Numbers);
	print "Original Sequence:<br>";

	$sorted = sort($Numbers);	
 	print "Sorted Numbers: $sorted";
	echo implode(" ",$Numbers);
	print "<br>Largest Number: $big<br>";
	print "Smallest Number: $small<br>";
	print "Average Number: $average<br>";}
else {
	print "<font color='red'>Invalid Input Grades must be Numeric</font>";}
		
	 
	?>
$var = array(1,2,3,4,5);
foreach($var as $number){
    echo $number;
}
0

I need help with displaying the original order of the numbers selected, and when i try to do "is_numeric" my output goes blank or it only displays the error message i created.

0

I need help with displaying the original order of the numbers selected, and when i try to do "is_numeric" my output goes blank or it only displays the error message i created.

did you even see the example above?

0

The original numbers come form the text boxes on the form which is an array, trying to figure out why it won't display the Values entered by the user. my output for the "Original Sequence" returns the word "Array" instead of the numbers in original order. the example above doesnt help me

0

Here is what i have now:

<?php

if (isset($_POST['numbers']))

{ 
    $Numbers = $_POST['numbers'];
	$big = max($Numbers);  
	$small = min($Numbers);
	$average = array_sum($Numbers) / count($Numbers);
	$original = ("$Numbers");
	print "<font color='LightSlateGrey'>Original Sequence: $original</font><br>";

	$sorted = sort($Numbers);	
 	print "Sorted Numbers: $sorted";
	echo implode(" ",$Numbers);
	print "<br><font color='green'>Largest Number: $big</font><br>";
	print "<font color='purple'>Smallest Number: $small</font><br>";
	print "<font color='aqua'>Average Number: $average<br></font><br>";}
else {
	print "<font color='red'>All Entries Must be Numeric</font>";}
		
	 
	?>
0

Here's the output

Array ( [numbers] => Array ( [0] => 1 [1] => 4 [2] => 6 [3] => 7 [4] => 8 [5] => 9 [6] => 99 [7] => 21 ) )

0

Here's the output

Array ( [numbers] => Array ( [0] => 1 [1] => 4 [2] => 6 [3] => 7 [4] => 8 [5] => 9 [6] => 99 [7] => 21 ) )

Nice, it means a form is working. Now use this code (I added for loop and removed implode stuffs). Check if that is what you want

<?php

if (isset($_POST['numbers'])){ 
    $numbers = $_POST['numbers'];
	$big = max($numbers);  
	$small = min($numbers);
	$average = array_sum($numbers) / count($numbers);
	
	print "<font color='LightSlateGrey'><strong>Original Sequence:</strong><br>";
	foreach($numbers as $num){
	    print $num."<br />"
	} 
	print "</font>";
	
	print "<br><font color='green'>Largest Number: $big</font><br>";
	print "<font color='purple'>Smallest Number: $small</font><br>";
	print "<font color='aqua'>Average Number: $average<br></font><br>";
	
}
0

That doesnt help, all it does is output the sorted numbers horizontally. Am i not being clear enough? As of now my output looks like this:


Original Sequence: Array
Sorted Numbers: 16 7 9 12 17 34 65 99
Largest Number: 99
Smallest Number: 6
Average Number: 31.125

I need the Original Sequence to output the numbers in the order entered by the user, not "Array", also on the "sorted numbers" row their shouldnt be a "1" in front of the output because the lowest number is "6" not "16"

Hope that explains my dilemma a bit more

0

Original Sequence: Array
Sorted Numbers: 16 7 9 12 17 34 65 99
Largest Number: 99
Smallest Number: 6
Average Number: 31.125

first your question is not clear as for what you want to archieve and how you try to. That being said in my code there is no Sorted number and I wonder why would foreach loop print "Array"

0

Well i don't know any other way to explain it to you, i think i was clear enough, the sorted number has been in my code the entire time. all i needed was to be able to print the numbers from the form's textboxes in the order that the user inputs them.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.