Today we learn how to make our programs interactive and responsive!
From one-way messages to two-way conversations
✨ Let's make programs that listen and respond! ✨
Master scanf()
Get user input like a pro
Advanced printf()
Beautiful formatting tricks
Input Validation
Handle errors gracefully
Interactive Programs
Real conversations with code
User-Friendly Design
Programs people love to use
Build Applications
Your first interactive tools
Whole numbers like 42, -10, 0
%d
Decimal numbers like 3.14, -5.7
%f
Single letters like 'A', 'x', '5'
%c
Which format specifier displays whole numbers?
Think about it...
Challenge 1: Did you declare 3 variables with your personal info?
Challenge 2: Could you use printf to display all your variable values?
Challenge 3: Any cool discoveries with format specifiers?
Bonus: Did you experiment with different data types?
🌟 Let's see your amazing variable programs!
💻 Computer: "Hello! I can talk to you!"
💻 Computer: "I'm going to tell you my age: 25"
💻 Computer: "Goodbye!"
😢 You: "But I wanted to tell you MY age!"
🔄 Today we fix this! Time for REAL conversations!
Reads what the user types in real-time
Puts input directly into variables
Knows numbers from letters automatically
Gets input exactly when your program needs it
scanf() = "scan formatted" - scans and formats user input like magic!
"Give me the ADDRESS where to store this data"
"Hey scanf, put the input IN this memory box!"
Program: Hi! What's your age?
You type: 13
Program: Wow! You are 13 years old!
Let's write a program together that asks for your name and favorite number!
🚀 Let's code this together step by step!
Integer
Perfect for whole numbers!
Float (6 decimals)
Shows: 3.140000
Float (2 decimals)
Shows: 3.14
Single character
Shows: A
Integer with width 5
Shows: 42
Padded with zeros
Shows: 00000042
Program: Enter two numbers:
You type: 15 27
Program: 15 + 27 = 42
Should be:
Should be:
Should be:
Always add a space before %c to catch leftover newlines from previous inputs!
scanf("%d", &price);
scanf("%f", &price);
scanf("%c", &price);
scanf("%f", price);
Click your answer!
Better than just: scanf("%d", &age);
Users know exactly what to do!
Let users know their input was received!
Make the output interesting and fun!
Create a program that:
Program: Hi! What's your name?
You: Rahul
Program: Hello Rahul! Enter two numbers:
You: 10 5
Program: Rahul's Math Results:
10 + 5 = 15
10 - 5 = 5
10 × 5 = 50
You've transformed from static output to dynamic interaction!
Arithmetic Operations & Math Magic
We'll make computers solve complex math problems automatically!
What math problems would you like your program to solve for you?
🎊 Awesome work! Your programs are now interactive! 🎊