Guest User

Untitled

a guest
Feb 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <?php
  2. $tehteLiik = "Puudub";
  3. $arv1 = 0;
  4. $arv2 = 0;
  5.  
  6. if( Olemas( $_POST[ 'arv1' ] ) && Olemas( $_POST[ 'arv2' ] ) )
  7. {
  8. $arv1 = $_POST[ 'arv1' ];
  9. $arv2 = $_POST[ 'arv2' ];
  10. }
  11.  
  12. if( Olemas( $_POST[ 'tehe' ] ) )
  13. {
  14. $tehteLiik = $_POST[ 'tehe' ];
  15.  
  16. switch( $tehteLiik )
  17. {
  18. case "Liida":
  19. {
  20. $vastus = Liida( $arv1, $arv2 );
  21. }
  22. break;
  23.  
  24. case "Lahuta":
  25. {
  26. $vastus = Lahuta( $arv1, $arv2 );
  27. }
  28. break;
  29.  
  30. case "Korruta":
  31. {
  32. $vastus = Korruta( $arv1, $arv2 );
  33. }
  34. break;
  35.  
  36. case "Jaga":
  37. {
  38. $vastus = Jaga( $arv1, $arv2 );
  39. }
  40. break;
  41. }
  42.  
  43. $html = '<h2>Tehte vastus: </h2><br />' . $vastus . '';
  44. }
  45.  
  46. function Liida( $arv1, $arv2 )
  47. {
  48. return $arv1 + $arv2;
  49. }
  50.  
  51. function Lahuta( $arv1, $arv2 )
  52. {
  53. return $arv1 - $arv2;
  54. }
  55.  
  56. function Korruta( $arv1, $arv2 )
  57. {
  58. return $arv1 * $arv2;
  59. }
  60.  
  61. function Jaga( $arv1, $arv2 )
  62. {
  63. return $arv1 / $arv2;
  64. }
  65.  
  66. function Olemas( $parameeter )
  67. {
  68. if( isset( $parameeter ) )
  69. return true;
  70. else
  71. return false;
  72. }
  73. ?>
  74.  
  75. <html>
  76. <head>
  77. <title>Programmeerimine - Tehted</title>
  78. </head>
  79. <body>
  80. <div id="container">
  81. <form>
  82. <label for="arv1">Esimene arv</label>
  83. <input type="text" name="arv1" />
  84. <label for="arv2">Teine arv</label>
  85. <input type="text" name="arv2" />
  86.  
  87. <label for="tehe">Liida</label>
  88. <input type="radio" name="tehe" value="Liida" />
  89. <label for="tehe">Korruta</label>
  90. <input type="radio" name="tehe" value="Korruta" />
  91. <label for="tehe">Jaga</label>
  92. <input type="radio" name="tehe" value="Jaga" />
  93. </form>
  94.  
  95. <p>
  96. <?php echo $html; ?>
  97. </p>
  98. </div>
  99. </body>
  100. </html>
Add Comment
Please, Sign In to add comment