nschmutz Posted June 21, 2010 Share Posted June 21, 2010 I need to write a script with the following parameters: -generate a function which takes a number between 1 and 20 (inclusive), and one of square root, square or cube as the operation to be performed on the number. The function should return the square root, square or cube of the given number based on user input. - draw an HTML form to receive from the user the number in a textbox, and the operation to be performed in a drop-down menu - display the result, stating the number entered and the chosen operation (square root, square or cube.) (For example, display "The square of 3 is 9.") Round the result to three decimal places; i.e., there should be at most three digits after the decimal separator period - The textbox and the drop-down should be sticky, and the form should be redrawn when the message is displayed. - If anything other than a number between 1 and 20 is entered (a number less than 1 or greater than 20, or a non-numeric value, etc.) the script should issue a warning, and also redraw the form with the illegitimate value entered. - will have to use "switch" within the function declaration Appreciate any help you can give. Quote Link to comment https://forums.phpfreaks.com/topic/205378-generate-a-function/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 21, 2010 Share Posted June 21, 2010 A) What problem or error are you getting with your code that you need help with or what specific programming question do you have? B) We don't do homework, we help with specific coding problems, errors, or questions you have. C) We don't write code based on lists of requirements. There is a freelancing forum section if you want someone to do this for you. Quote Link to comment https://forums.phpfreaks.com/topic/205378-generate-a-function/#findComment-1074818 Share on other sites More sharing options...
ignace Posted June 21, 2010 Share Posted June 21, 2010 if (1 <= $input['number'] && $input['number'] <= 20) // 1 <= x <= 20 { switch ($input['type']) { case 'square_root': $output = factory('square_root')->calc($input['number'])->toString(); // 'The square root of $input['number'] is $x' break; case 'square': $output = factory('square')->calc($input['number'])->toString(); // 'The square of $input['number'] is $y' break; case 'cube': $output = factory('cube')->calc($input['number'])->toString(); // 'The cube of $input['number'] is $z' break; } echo $output; } Should get you started. Quote Link to comment https://forums.phpfreaks.com/topic/205378-generate-a-function/#findComment-1075162 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.