Write a program to give discount of 20% if age is less than 15 or greater than 60 to customer otherwise gives only 5% discount.

Sure! Here's a step-by-step guide to write a program that gives a discount of 20% if the age is less than 15 or greater than 60, and a discount of 5% otherwise:

Step 1: Get the customer's age as input from the user.
Step 2: Check if the age is less than 15 or greater than 60.
Step 3: If the condition in Step 2 is true, calculate the discount amount as 20% of the total price. Otherwise, calculate it as 5%.
Step 4: Subtract the discount amount from the total price to calculate the final price.
Step 5: Display the final price to the user.

Here's a Python implementation of the above program:

```python
def calculate_discount(age, total_price):
if age < 15 or age > 60:
discount = 0.2 # 20% discount
else:
discount = 0.05 # 5% discount

discount_amount = total_price * discount
final_price = total_price - discount_amount

return final_price

# Example usage
age = int(input("Enter customer's age: "))
total_price = float(input("Enter total price: "))

final_price = calculate_discount(age, total_price)
print("Final price: $" + str(final_price))
```

Note: This code assumes that the total price provided by the user is a float value and the customer's age is an integer value.

Sure! Here's an example of a program that calculates the discount based on the provided conditions:

```python
def calculate_discount(age):
if age < 15 or age > 60:
discount = 0.2
else:
discount = 0.05

return discount

# Example usage
customer_age = int(input("Enter customer's age: "))
discount_percentage = calculate_discount(customer_age)

print("Discount Percentage:", discount_percentage * 100, "%")
```

Explanation:
1. The program defines a function called `calculate_discount` that takes the `age` as an input.
2. Inside the function, an `if` statement checks whether the age is less than 15 or greater than 60. If either condition is true, the discount is set to 20% by assigning the value `0.2` to the `discount` variable.
3. If neither of the conditions is true, the discount is set to 5% by assigning the value `0.05` to the `discount` variable.
4. The function returns the calculated discount.
5. The program prompts the user to enter the customer's age, which is then converted to an integer using `int(input())`.
6. The `calculate_discount` function is called with the provided age, and the resulting discount percentage is assigned to the `discount_percentage` variable.
7. Finally, the discount percentage is printed to the console by multiplying it by 100 and appending a "%" symbol.

By following these steps, the program dynamically calculates the appropriate discount based on the customer's age and displays the result.

double discount = 0.05;

if (age < 15 || age > 60) discount = 0.20;

price *= (1 - discount);

This isn't a complete program of course, as the question doesn't specify where the age comes from (entered by the user, or stored in an existing data structure?). It just includes how the discount is calculated, as well as how the discount affects the price. Basically, what I've written here can be plugged into an existing program that already defines the variables "age" and "price".