0% found this document useful (0 votes)
2 views2 pages

Programming concepts class5

The document outlines various applications of conditionals in programming, including user authentication, e-commerce discounts, automated email notifications, smart home automation, and online form validation. Each section provides a code example in different programming languages to illustrate how conditionals are used in these scenarios. The use cases demonstrate the practical implementation of conditionals in real-world applications.

Uploaded by

Federico Czyrka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Programming concepts class5

The document outlines various applications of conditionals in programming, including user authentication, e-commerce discounts, automated email notifications, smart home automation, and online form validation. Each section provides a code example in different programming languages to illustrate how conditionals are used in these scenarios. The use cases demonstrate the practical implementation of conditionals in real-world applications.

Uploaded by

Federico Czyrka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

### **1.

User Authentication (Login System)**


Conditionals check if a user�s credentials are correct before granting access.

#### **Example in JavaScript:**


```javascript
function login(username, password) {
if (username === "admin" && password === "secure123") {
console.log("Login successful!");
} else {
console.log("Invalid credentials. Please try again.");
}
}
```
- **Use Case:** Websites use conditionals to verify username/password combinations.

---

### **2. E-Commerce: Apply Discounts**


Conditionals determine whether a customer qualifies for a discount.

#### **Example in Python:**


```python
def apply_discount(price, is_member):
if is_member:
return price * 0.9 # 10% discount
else:
return price
```
- **Use Case:** Online stores give discounts based on user membership status.

---

### **3. Automated Email Notifications**


Conditionals help customize notifications based on a user�s subscription
preferences.

#### **Example in C#:**


```csharp
string subscriptionType = "premium";

if (subscriptionType == "premium") {
Console.WriteLine("Sending premium newsletter...");
} else {
Console.WriteLine("Sending standard newsletter...");
}
```
- **Use Case:** Businesses send different email content based on subscription type.

---

### **4. Smart Home Automation**


Conditionals help control devices based on environmental data.

#### **Example in JavaScript:**


```javascript
let temperature = 30;

if (temperature > 25) {


console.log("Turning on air conditioning...");
} else {
console.log("AC is off.");
}
```
- **Use Case:** Smart thermostats automatically adjust settings based on room
temperature.

---

### **5. Online Forms: Validating Inputs**


Conditionals ensure required fields are filled before submission.

#### **Example in JavaScript:**


```javascript
function validateForm(name, email) {
if (!name || !email) {
console.log("Please fill out all required fields.");
} else {
console.log("Form submitted successfully!");
}
}
```
- **Use Case:** Websites prevent form submission if required fields are empty.

---

You might also like