Session 2: Getting Input from Users
Your Name
- 3 minutes read - 595 wordsSession 2: Getting Input from Users
Make your programs interactive by learning to get input from users. Understand the difference between input and output operations.
🎯 Key Skills You'll Learn:
- cin for input
- string variables
- User interaction
🚀 Session Project:
Mad Libs Generator
Learning Objectives
- Learn to get input from users
- Understand the difference between input and output
- Create interactive programs
Warm-up (5 minutes)
Run your ASCII art program from last session. Does it work? If not, what error messages do you see?
New Concept Introduction (20 minutes)
Input vs Output
- Output: Showing information to the user (we learned
cout) - Input: Getting information from the user (new:
cin)
Getting User Input
|
|
Key points:
string name;creates a “variable” to store textcin >>gets input from the user- We can combine text and variables in output using
<<
Common Input Types
|
|
Hands-on Practice (25 minutes)
Exercise 1: Personal Info Collector (10 minutes)
|
|
Exercise 2: Simple Calculator (15 minutes)
|
|
Challenge/Quiz (10 minutes)
Challenge: Mad Libs Generator Create a program that asks for:
- An adjective
- A noun
- A verb
- A place
Then creates a funny sentence using their inputs.
Validation Prompt
🤖 AI Validation Prompt
Copy this prompt and your code to ChatGPT or Claude for instant feedback:
```
I'm learning C++ and just completed Session 2. Here's my solution to the Mad Libs Generator challenge:
[PASTE YOUR CODE HERE]
The challenge was: Create a program that asks for an adjective, noun, verb, and place, then creates a funny sentence using their inputs.
Please check if my solution:
1. Compiles correctly
2. Uses cin to get user input
3. Uses cout to display a creative sentence
4. Stores input in appropriately named variables
If there are issues, please explain what's wrong and give me a hint to fix it (don't give me the complete solution).
```
What You Learned
- ✅ How to get input from users with
cin - ✅ Creating variables to store different types of data
- ✅ Combining user input with program output
- ✅ Basic interactive program structure
Next Session Preview
In Session 3, you’ll dive deeper into variables and learn about different data types like integers, decimals, and text!