Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Overall outline of the question
- // peopleOnBus = people on the bus
- // peopleAtBusStop = people who want to get on the bus
- // busCapacity = Total capacity
- function checkFormValues ($formValue){
- if (isset($_POST[$formValue]))
- {
- $result = $_POST[$formValue];
- }
- else
- {
- $result = 0; //change to return to form RETAINING values
- //echo "<a href='bus.php'>Back</a>";
- }
- return $result;
- }
- $peopleOnBus = 0;
- $peopleAtBusStop = checkFormValues('peopleAtBusStop');
- $busCapacity = checkFormValues('busCapacity');
- $peopleOff = checkFormValues('peopleOff');
- //Process
- $totalpeople = $peopleOnBus + $peopleAtBusStop - $peopleOff;
- if($peopleOff > $busCapacity)
- {
- echo "The values inserted are not valid. Go back to the previous page!";
- }
- else if ($peopleOff > $peopleOnBus)
- {
- echo "The values inserted are not valid. Go back to the previous page!";
- }
- else
- {
- echo "The bus has a capacity of $busCapacity";
- echo "<br>";
- // Question 1: Capacity is less than total people
- if ($totalpeople > $busCapacity)
- {
- $difference = $totalpeople - $busCapacity;
- echo "$peopleAtBusStop people tried to get on";
- echo "<br>";
- echo $peopleAtBusStop - $difference . ' could get on';
- echo "<br>";
- echo "$difference people could not get on, too bad";
- }
- //Question 2: Spare seats
- else if ($totalpeople < $busCapacity)
- {
- $spareSeats = $busCapacity - $totalpeople;
- echo "$totalpeople people got on the bus, and there were $spareSeats spare seats";
- }
- // Question 3: Total capacity = total people
- else if ($totalpeople == $busCapacity)
- {
- echo "$peopleAtBusStop people tried to get on the bus";
- echo "<br>";
- echo "Everyone could get on the bus yay";
- }
- }
- ?>
- <hr>
- <a href='bus.php'>Back</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement