Lesson 7, More Looping and Decisions
Part 7

We have been tasked with writing a program for ski lift at a resort. The ski lift chair holds three people and has a maximum capacity of 750 lbs. There is a concern that the maximum capacity of the ski lift chair might be exceed by three husky riders thus exposing the resort to possible lawsuits.  The solution was to have a all-weather scale located at the start of the lift.  The person checking lift tickets would be required to record the weights of each of the individuals riding each chair into a compute program.  The program would then tell the lift ticket checker how much the combined weight of the riders is and whether they can ride on the ski lift chair. The program will request the next weight and then tell the user what the accumulated weight of the riders is and how many riders have been weighed for the ride.  If the weight exceeds 750 or once the three person limit has been reached the user would be informed of this and the program will not ask for any more weights.  The program must also tell the user how many riders, total weight, and if the ride can be started or not

In a piece of paper write down the following breakdown of this problem into a problem statement:

Assumptions (scope):
Input (what's coming in):
Calculations:
Output (what's going out):

Answer

 

 

 

 

 

 

 

 

 

 

Problem Statement
Assumptions (what is the scope):
The lift will only hold three people
If the total weight of the riders with equipment is 750 lbs or less we can start the ride.
We can have less than three, but can not have more than three.
Input (What will be entered into our program):
The weight of rider
Calculations:
Total weight = Total Weight + new weight.
number of riders = number of riders + 1
Output:
The total weight of the riders
If greater than 750 then "You have exceeded the 750 pound limit
If three person limit has been reached "You have reached the 3 person limit"
If total is less than or equal to  750 lbs "The ride is safe to start"
If total is greater than 750 lbs then "STOP!  The ride is NOT safe to start"

Now you need to write the human algorithm (the simple steps necessary to solve this problem):
Click to see the human algorithm

 

 

 

 

 

 

 

 

 

 

 

 

Human Algorithm
1.  Get the weight of the rider
2.  Add the new weight to the existing weight
3.  Add 1 to the number of riders
4.  If total weight is greater than 750 then output total wt exceed and go to 8
5.  If number of riders is 3 then output "the 3 person limit has been met" then go to 8
6.  Ask if there's another rider. 
7.  If there's another rider go to 1 
8.  Output "The total weight of the riders is (add total weight)
9.  If total is less than or equal to  750 lbs Output "The ride is safe to start"
10.  If total is greater than 750 lbs then Output "STOP!  The ride is NOT safe to start"

Next you need to flow chart this problem
answer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Flow Chart

Next you need to code this problem:
answer

 

 

 

 

 

 

 

 

 

Code:
<script language=vbscript>
Option Explicit
Dim anotherrider, nostart,ridernum, riderwt, ridertotal

anotherrider = "yes" '<-- starts the program with "yes" so the loop starts without asking
nostart = " " '<-- places a blank space in nostart so that it won't mess up our output if the ride is a go

Do while anotherrider = "yes"
    ridernum = ridernum +1 '<-- Counts the rider
    riderwt = inputbox("What is the rider's weight")
    ridertotal = ridertotal + Cint(riderwt) '<-- Cummulates the riders weight
    If ridertotal > 750 then
        Msgbox("You have exceeded the ride capacity of 750 lbs. The total is " & ridertotal & ". The number of riders is " & ridernum)
        anotherrider = "no" '<-- stops the loop
        nostart = " not " '<-- allows us output that the rider cannot start
    ElseIf ridernum = 3 then
        Msgbox("You have reached the ride's capacity of 3 riders with a weight of " & ridertotal)
        anotherrider = "no"
    Else
        Msgbox("The number of riders so far is " & ridernum & " and the weight so far is " & ridertotal)
        anotherrider = inputbox("Is there another rider?")
    end if
Loop

Document.write "The total number of riders is " & ridertotal
Document.write "<br> The number of riders is " & ridernum
Document.write "<br> You can" & nostart & "start the ride"
</script>