Calculate sum of n
Solution
....- Enter a number n and make the sum from 1 up to n
- Show the complete number sequence, including the result
- The input is a text field (not a number field), which
means that you have to do some server side validation:
- Integers must be limited between 1 and 100
- Floats must be typecasted to an integer
- Strings must be converted to 1
- The form is sent via GET and is processed on the same page. Make sure that the form remains visible and the text field still contains the entered number when the form is processed and the sum is shown.
Tips
- Use the PHP function
is_numeric()
to test whether a variable is numeric - It might be easier when you first process the inputs (calculate and show the sum) on a different page. If this works, you can try to bring it all together (on one page).