Click here to Skip to main content
15,942,094 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to write a php program that prompts user to enter as many numbers as he/she wishes. The termination of number entry should be done by the letter N or n. Once the number entry is completed the program is expected to print the max, min, average, mode and median of the numbers alongside with a histogram.

I just want to learn how to take number from a user as many number as he/she wishes and make the termination.

What I have tried:

HTML
<html>
<body>
<form action="example.php" method="post>
Enter a number:
<input type="number_format" name="number"> <br> <br>
<input type="submit" value="submit">
</form>
</body>
</html>


------

PHP
<?php

$num = $_POST=['number'];



?>
Posted
Updated 18-Jul-23 8:50am
v3

PHP
$num = $_POST['number'];

Find ten differences. :-)

—SA
 
Share this answer
 
Comments
arda gökdağ 14-May-16 15:56pm    
thank you:)
Sergey Alexandrovich Kryukov 14-May-16 16:24pm    
You are welcome. Will you accept the answer formally?
—SA
Hi! First of all Im a C# dev and has't used PHP for a couple of years now. But PHP is mostly used as a server-side script, you can use a command-promt but this is rare in PHP. (PHP has a strong association to C, so most devs create librarys in C instead)

What Im trying to say is that you don't need a terminator, looking at your code you don't seem to create an RIA application. If you are, you "need" to use a JavaScript to find the terminator and then submit the numbers to the server, but JavaScript can do all you want to do. But I will show you the basic code to get you going. (Im not adding code for your operations like max and min)

This code will take the numbers in a string divided by a comma, you can change this to a space as well if you wish.

PHP
$delimiter = ',' // The charecter to divide the numbers
// $delimiter = ' ' Use this line to divide numbers by a space

$numbers = explode($delimiter, $_POST['number']);


You can find the documentation of the explode function at php.net wich takes an string and break it into an Array. The first argument is the char that divides the numbers. But I still Think you should do all this in jQuery or in another JavaScript library.
 
Share this answer
 
v2
Comments
arda gökdağ 14-May-16 15:57pm    
thank you very much :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900