Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php
  2. //Overall outline of the question
  3. // peopleOnBus = people on the bus
  4. // peopleAtBusStop = people who want to get on the bus
  5. // busCapacity = Total capacity
  6.  
  7. function checkFormValues ($formValue){
  8. if (isset($_POST[$formValue]))
  9. {
  10. $result = $_POST[$formValue];
  11. }
  12. else
  13. {
  14. $result = 0; //change to return to form RETAINING values
  15. //echo "<a href='bus.php'>Back</a>";
  16. }
  17.  
  18. return $result;
  19. }
  20.  
  21. $peopleOnBus = 0;
  22. $peopleAtBusStop = checkFormValues('peopleAtBusStop');
  23. $busCapacity = checkFormValues('busCapacity');
  24. $peopleOff = checkFormValues('peopleOff');
  25.  
  26. //Process
  27. $totalpeople = $peopleOnBus + $peopleAtBusStop - $peopleOff;
  28.  
  29. if($peopleOff > $busCapacity)
  30. {
  31. echo "The values inserted are not valid. Go back to the previous page!";
  32. }
  33.  
  34. else if ($peopleOff > $peopleOnBus)
  35. {
  36. echo "The values inserted are not valid. Go back to the previous page!";
  37. }
  38.  
  39. else
  40. {
  41. echo "The bus has a capacity of $busCapacity";
  42. echo "<br>";
  43.  
  44. // Question 1: Capacity is less than total people
  45. if ($totalpeople > $busCapacity)
  46. {
  47. $difference = $totalpeople - $busCapacity;
  48. echo "$peopleAtBusStop people tried to get on";
  49. echo "<br>";
  50. echo $peopleAtBusStop - $difference . ' could get on';
  51. echo "<br>";
  52. echo "$difference people could not get on, too bad";
  53. }
  54.  
  55. //Question 2: Spare seats
  56. else if ($totalpeople < $busCapacity)
  57. {
  58. $spareSeats = $busCapacity - $totalpeople;
  59. echo "$totalpeople people got on the bus, and there were $spareSeats spare seats";
  60. }
  61.  
  62. // Question 3: Total capacity = total people
  63. else if ($totalpeople == $busCapacity)
  64. {
  65. echo "$peopleAtBusStop people tried to get on the bus";
  66. echo "<br>";
  67. echo "Everyone could get on the bus yay";
  68. }
  69.  
  70. }
  71.  
  72. ?>
  73. <hr>
  74. <a href='bus.php'>Back</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement