1 / 18

Session 7: Decision Making - Basic Conditionals

🤔 Teaching Computers to Make Choices

Today we give our programs the power to think and decide!

From simple yes/no questions to smart decision-making

✨ Programs that can think and choose! ✨

🎯 Today's Decision-Making Mission

🤔

Master if Statements
Basic decision making

⚖️

Comparison Operators
==, !=, >, <, >=, <=

Boolean Logic
True/false concepts

🎮

Interactive Programs
Programs that respond differently

🚦

Control Flow
Direct program behavior

🏆

Age Classifier
Build smart categorization

🧮 Quick Arithmetic Review!

➕ What's 15 + 27?

42

📏 What does PEMDAS stand for?

Parentheses, Exponents, Multiplication, Division, Addition, Subtraction

🔢 What's 17 % 5?

2 (remainder)

🤖 Which operator gives us the remainder?

% (modulus)

🏠 Mathematical Creations Showcase!

🎉 Let's see your math programming magic!

🧮 Super Calculator: Show us your 5-operator calculator with menu!
🏠 Room Calculator: Demonstrate area and perimeter calculations!
Time Converter: Display your seconds-to-time converter!
💰 Shopping Calculator: Show tax and change calculations!
🎯 PEMDAS Mastery: Share your complex expression predictions!
🔍 Modulus Explorer: Demonstrate even/odd checking!

🌟 Amazing mathematical programming skills!

🤔 Programs Need to Make Decisions Too!

🚦

🚗 In Real Life

If traffic light is red → STOP

If traffic light is green → GO

📱 In Apps

If password is correct → Login

If password is wrong → Try again

🎮 In Games

If player reaches goal → Win!

If player falls → Game over

💻 In Our Programs

If age >= 13 → "You're a teenager!"

If score > 90 → "Excellent work!"

🚪 Meet the 'if' Statement - Your Decision Maker!

Basic if Statement Structure:

if (condition_is_true) { // This code runs only if condition is true printf("The condition was true!\n"); }

The Magic Formula:

if (QUESTION) { ANSWER }

🎯 Key Points:

  • Condition goes in parentheses ( )
  • Code to execute goes in braces { }
  • If condition is false, code inside { } is skipped
  • If condition is true, code inside { } runs

⚖️ Meet the Comparison Operators!

==

Equal To

Are they exactly the same?

age == 13
!=

Not Equal

Are they different?

score != 0
>

Greater Than

Is left side bigger?

grade > 90
<

Less Than

Is left side smaller?

temp < 32
>=

Greater/Equal

Bigger or same?

age >= 16
<=

Less/Equal

Smaller or same?

speed <= 55

💻 Your First Decision-Making Program!

#include <stdio.h> int main() { int age; printf("Enter your age: "); scanf("%d", &age); // Decision making! if (age >= 13) { printf("You're a teenager! 🎉\n"); } if (age >= 18) { printf("You're an adult! 🎓\n"); } if (age < 13) { printf("You're still a kid! 🧒\n"); } return 0; }

🎯 Test Different Ages:

  • Try age 10 → "You're still a kid!"
  • Try age 15 → "You're a teenager!"
  • Try age 20 → "You're a teenager!" AND "You're an adult!"

🚨 Common Comparison Mistakes to Avoid!

❌ Single = instead of ==

if (age = 13) // WRONG - This assigns!

Correct: if (age == 13) - This compares!

❌ Missing parentheses

if age > 10 // WRONG - Missing ( )

Correct: if (age > 10)

❌ Wrong comparison direction

if (18 < age) // Confusing order

Better: if (age > 18) - More natural

✅ Pro Tips!

  • Always use == for comparison
  • Put variable on left, value on right
  • Use meaningful variable names
  • Test with different values

🧠 Comparison Operators Quiz!

🎯 If age = 15, which condition is TRUE?

A) age == 13

Is 15 equal to 13?

B) age > 10

Is 15 greater than 10?

C) age < 14

Is 15 less than 14?

D) age >= 15

Is 15 greater than or equal to 15?

Multiple answers can be correct!

✅ Understanding True and False

🤖

How Computers Think:

Question: Is 15 > 10?
Computer Brain: 15 is greater than 10
Answer: TRUE ✅
Question: Is 8 == 12?
Computer Brain: 8 is not equal to 12
Answer: FALSE ❌
Question: Is 7 <= 7?
Computer Brain: 7 is equal to 7 (satisfies <=)
Answer: TRUE ✅

🎯 If condition is TRUE → Code runs. If FALSE → Code skips!

🎓 Build a Grade Classifier!

#include <stdio.h> int main() { int score; printf("Enter your test score (0-100): "); scanf("%d", &score); printf("Your score: %d\n", score); // Grade classification if (score >= 90) { printf("Grade: A - Excellent! 🌟\n"); } if (score >= 80 && score < 90) { printf("Grade: B - Good job! 👍\n"); } if (score >= 70 && score < 80) { printf("Grade: C - Keep working! 📚\n"); } if (score < 70) { printf("Grade: Needs Improvement 💪\n"); } return 0; }

🗺️ Choose Your Adventure Challenge!

🎮 Build Your First Decision-Based Game

Let's create a simple adventure with choices!

🗡️ Adventure Story Structure:

1. Set the Scene: You're exploring a mysterious cave...
2. Present Choice: Do you go left or right? (Enter 1 or 2)
3. Use if Statements: Different outcomes for each choice
4. Add Consequences: Each path leads to different results

🚀 Let's code this adventure together!

👶 Age Category Classifier Challenge!

#include <stdio.h> int main() { int age; printf("=== AGE CATEGORY CLASSIFIER ===\n"); printf("Enter someone's age: "); scanf("%d", &age); // Age classification system if (age <= 2) { printf("Category: Baby 👶\n"); } if (age >= 3 && age <= 12) { printf("Category: Child 🧒\n"); } if (age >= 13 && age <= 19) { printf("Category: Teenager 🎸\n"); } if (age >= 20) { printf("Category: Adult 👨‍💼\n"); } return 0; }

🔗 Combining Conditions with && (AND)

The && (AND) Operator

Both conditions must be true:
if (age >= 13 && age <= 19)
TRUE only if age is 13 OR 14 OR 15 OR 16 OR 17 OR 18 OR 19
Real-world example:
if (score >= 90 && attendance >= 95)
Gets honor roll only if BOTH score AND attendance are high

✅ Both True = TRUE

age = 15, condition: age >= 13 && age <= 19

Result: TRUE (both conditions met)

❌ One False = FALSE

age = 25, condition: age >= 13 && age <= 19

Result: FALSE (age not <= 19)

🔐 Password Checker Program

#include <stdio.h> int main() { int password; int secret_code = 1234; printf("🔐 Enter the secret code: "); scanf("%d", &password); if (password == secret_code) { printf("✅ Access Granted! Welcome! 🎉\n"); printf("🏠 You're now in the secret clubhouse!\n"); } if (password != secret_code) { printf("❌ Access Denied! Wrong code! 🚫\n"); printf("🔒 The secret remains protected!\n"); } return 0; }

🎯 Test Your Security System:

  • Try 1234 → Access Granted!
  • Try 1111 → Access Denied!
  • Try 5678 → Access Denied!

🛠️ Your Turn: Build Decision Programs!

💡 Coding Challenges

🌡️ Temperature Checker

If temp > 80 → "It's hot!"

If temp < 60 → "It's cold!"

🎯 Score Motivator

If score >= 95 → "Perfect!"

If score < 50 → "Study more!"

🕐 Bedtime Reminder

If hour >= 22 → "Time for bed!"

If hour <= 6 → "Good morning!"

🎮 Game Level Checker

If level >= 10 → "Expert player!"

If level == 1 → "Welcome, beginner!"

🚀 Pick one and let's code it together!

🎲 Preview: Number Guessing Game Logic

#include <stdio.h> int main() { int secret_number = 42; int guess; printf("🎲 Guess my number (1-100): "); scanf("%d", &guess); if (guess == secret_number) { printf("🎉 Perfect! You got it!\n"); } if (guess > secret_number) { printf("📉 Too high! Try a smaller number.\n"); } if (guess < secret_number) { printf("📈 Too low! Try a bigger number.\n"); } printf("The secret number was: %d\n", secret_number); return 0; }

🎯 Next Week Preview:

We'll learn if-else statements to make this game even smarter and avoid repeating code!

🏆 Decision-Making Mastery Achieved!

🤔 if Statement Master
⚖️ Comparison Expert
✅ Boolean Logic Pro
🎯 Classifier Builder
🔐 Security System Creator
🎮 Game Logic Designer

Your programs can now think and make decisions! 🧠

You've unlocked the power of intelligent programming!

🏠 Your Decision-Making Programming Mission!

📝 This Week's Challenges:

  • 🎓 Complete Grade Classifier - Add more grade categories and motivational messages
  • 🌡️ Weather Advisory System - Give clothing advice based on temperature
  • 🚗 Speed Monitor - Check if driver is speeding and give warnings
  • 🎂 Birthday Party Planner - Suggest party size based on age
  • 🏆 Sports Performance Tracker - Classify athletic performance levels
  • 🔐 Multi-Level Password System - Different access levels for different codes

🚀 Next Week: Session 8

Advanced Conditionals - if-else and Logical Operators

We'll learn smarter ways to make decisions and handle multiple conditions!

🤔 Think About This Week:

What other decisions would you like your programs to make automatically?

🎊 Excellent work! Your programs are now intelligent decision-makers! 🎊