smgy94 Posted November 15, 2016 Share Posted November 15, 2016 I need to create a PHP programme that will allow me to Write a simple function that will take two numbers as augments and display their sum on screen. I'm brand new to php and stumped about how to do this simple task, can somebody give me the code to make this possible ?? i'd be SO grateful ! Quote Link to comment https://forums.phpfreaks.com/topic/302537-need-help-with-simple-program/ Share on other sites More sharing options...
requinix Posted November 15, 2016 Share Posted November 15, 2016 We can't just give you the code - you wouldn't be learning PHP if we did. But we'll help you write it. What have you done so far? Quote Link to comment https://forums.phpfreaks.com/topic/302537-need-help-with-simple-program/#findComment-1539325 Share on other sites More sharing options...
cyberRobot Posted November 15, 2016 Share Posted November 15, 2016 Perhaps the following will help: http://php.net/manual/en/functions.arguments.php There are some examples on how to display something based on the function arguments. You just need to figure out how to do the math aspect. Quote Link to comment https://forums.phpfreaks.com/topic/302537-need-help-with-simple-program/#findComment-1539328 Share on other sites More sharing options...
smgy94 Posted November 15, 2016 Author Share Posted November 15, 2016 <html> <p> <?php print rand(1,100); ?> </html> I'm a complete beginner, all I could figure out was how to create random numbers appear on screen, not adding two arguments Quote Link to comment https://forums.phpfreaks.com/topic/302537-need-help-with-simple-program/#findComment-1539329 Share on other sites More sharing options...
smgy94 Posted November 15, 2016 Author Share Posted November 15, 2016 Perhaps the following will help: http://php.net/manual/en/functions.arguments.php There are some examples on how to display something based on the function arguments. You just need to figure out how to do the math aspect. <!DOCTYPE html> <html> <body> <?php function sum($x, $y) { $z = $x + $y; return $z; } echo sum(11,11) . "<br>"; ?> </body> </html> is this correct ? thanks so much for helping Quote Link to comment https://forums.phpfreaks.com/topic/302537-need-help-with-simple-program/#findComment-1539331 Share on other sites More sharing options...
cyberRobot Posted November 15, 2016 Share Posted November 15, 2016 That seems fine. Did you try it out? Note that I'm unsure about the part highlighted below: ...simple function that will take two numbers as augments and display their sum on screen. That suggests the output would happen inside the function. Quote Link to comment https://forums.phpfreaks.com/topic/302537-need-help-with-simple-program/#findComment-1539333 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.