Branches are common programming constructs in programming applications

Full Answer Section

         

Sample Solution

         

Branching for Senior Guest Discounts

Here's how to create a branching construct to calculate a discounted hotel rate for guests 65 and older in various programming languages:

1. Pseudocode (Language-independent):

GuestAge = GetGuestAge()

IF GuestAge >= 65 THEN
  DiscountedRate = RegularRate * 0.8  (20% discount)
ELSE
  DiscountedRate = RegularRate
ENDIF

Display DiscountedRate

This pseudocode outlines the logic:

  • We get the guest's age.
  • We check if the age is greater than or equal to 65.
    • If yes, we calculate the discounted rate by multiplying the regular rate by 0.8 (100% - 20% discount).
    • If no, the discounted rate remains the same as the regular rate.
  • Finally, we display the discounted rate.

2. Translating to Specific Languages:

Here's an example in Python and Java:

Python:

Python
def calculate_discounted_rate(guest_age, regular_rate):
  if guest_age >= 65:
    discounted_rate = regular_rate * 0.8
  else:
    discounted_rate = regular_rate
  return discounted_rate

# Example Usage
guest_age = int(input("Enter guest age: "))
regular_rate = float(input("Enter regular rate: "))

discounted_rate = calculate_discounted_rate(guest_age, regular_rate)

print(f"Discounted rate for {guest_age} year old guest: ${discounted_rate:.2f}")

IS IT YOUR FIRST TIME HERE? WELCOME

USE COUPON "11OFF" AND GET 11% OFF YOUR ORDERS