PHP Code

Hi Guys,

I am having an issue to prepare a code for the following output in PHP . If anyone has idea how to prepare the code for following output e.g 1st and 2nd Number output will be in range of 0-40000 range of numbers by user input. It will add all integers in first input e.g 9872 will be 9+8+7+2 / 4 so Average 6.50. It will happen till second output number. >= 7 will be printed as heavy number and at end total count heavy numbers.

Enter 1st integer: 9872
Enter 2nd integer: 9884
Number Average Is Heavy
9872 6.50 No
9873 6.75 No
9874 7.00 No
9875 7.25 Yes
9876 7.50 Yes
9877 7.75 Yes
9878 8.00 Yes
9879 8.25 Yes
9880 6.25 No
9881 6.50 No
9882 6.75 No
9883 7.00 No
9884 7.25 Yes
Total Heavy Count: 6

Well, this sounds like it is a class project. But, glad to help some…

First, since you did not post any code, I will assume you have not started. Also that you are using PHP and HTML.
Therefore, you will need these sections to do this:

HTML to display a webpage.
HTML FORM to accept the user’s inputs for the two numbers.
PHP code below the form inputs to display the table of outputs and total the grand total.
(This would be a loop to move from 1st to 2nd number)

Here are tutorials on each of these.
http://www.w3schools.com/php/php_forms.asp Shows a page with HTML and a FORM
(You would need to alter the inputs to your two integers. And, get it to display those back on the page once submitted.)
http://www.w3schools.com/php/php_looping_for.asp Explains a “FOR” loop to move thru the numbers

Then, you would have to come up with a way to pull out the individual values of the numbers to add them up. This is
a little tricky as you need to divide them by 10 and grab the next part. We will help more once you get the row list working
of all the numbers…

So, experiment some and post your code when you get somewhere… Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service