Compute the Cost of Booking a Workspace

Problem statement

You want to book a workspace to increase your productivity. You have the option to choose from the following: an open office space, a dedicated desk, or a private office. You can also decide if you want a daily pass or a monthly pass for the workspace, and you wish to find out the cost based on your requirement. You have the following information:

Open office space

Pass Type Cost
Daily $20
Monthly $560

Dedicated desk

Pass Type Cost
Daily $10
Monthly $270

Private office

Pass Type Cost
Daily $40
Monthly $1100

The main steps in problem-solving

Understand the problem

Read the problem statement carefully. The inputs to the program will be the type of workspace and type of pass, and the output should be the total amount due.

Come up with a practical solution

Since we base our answer on conditions, we need to make use of IF, ELSE-IF, and ELSE statements. One approach to solving this problem is by specifying the type of space in conditional statements. Then, inside the conditional statement blocks, specify the pass type.

Implement your solution

Execute the solution on different test cases to verify it.

Pseudocode

INPUT space_type and pass_type
IF space_type == open office space
    IF pass_type == daily
        cost = 20
    ELSE
        cost = 560
ELSE IF space_type == dedicated desk
    IF pass_type == daily
        cost = 10
    ELSE
        cost = 270 
ELSE IF space_type == private office
    IF pass_type == daily
        cost = 40
    ELSE
        cost = 1100
ELSE
    cost = 0
    OUTPUT not a workspace option
OUTPUT cost

Explanation

Take the space_type and the pass_type as an input. Next, check if the space type is an open office space. If it is:

  • Check if the pass type is daily. If it is, then cost is set to 20.

  • If the pass type is not daily, cost equals 560.

If the space type is not an open office space, then we check if the space type is a dedicated desk. If space type is a dedicated desk:

  • We check if the pass type is daily or not. If it is daily, then cost equals 20, else cost equivalents 270.

If the space type is not an open office space or a dedicated desk, we check if the space type is a private office. If it is:

  • We set cost equal to 40 if the space type is daily and set cost equal to 1100 if the pass type is not daily.

If the space type is none of the above, we set cost to 0 and output “not a workspace option.”

Notice that, since the only pass types are daily and weekly, we know that if the pass type is not daily, then it is weekly. Also, we know that if the space type is not an open office space, a dedicated desk, or a private office, then it is not a correct option.

Flowchart

Get hands-on with 1400+ tech skills courses.