0
0
C++programming~15 mins

Using cin for input in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Using cin for input
📖 Scenario: You are creating a simple program that asks a user for their age and then displays it back to them.
🎯 Goal: Build a C++ program that uses cin to get the user's age and then prints it.
📋 What You'll Learn
Create an integer variable named age
Use cin to read the user's input into age
Print the age with a message using cout
💡 Why This Matters
🌍 Real World
Getting user input is essential for interactive programs like games, calculators, or data entry tools.
💼 Career
Understanding how to read input from users is a basic skill for software developers working on command-line tools or console applications.
Progress0 / 4 steps
1
Create an integer variable called age
Write a line of code to create an integer variable named age.
C++
Need a hint?

Use int age; to create the variable.

2
Use cin to read input into age
Write a line of code that uses std::cin to read the user's input into the variable age.
C++
Need a hint?

Use std::cin >> age; to get input from the user.

3
Print the age with a message using cout
Write a line of code that uses std::cout to print the message Your age is: followed by the value of age.
C++
Need a hint?

Use std::cout << "Your age is: " << age << std::endl; to print the message and value.

4
Run the program and display the output
Run the program and enter 25 when prompted. Write a line of code to print the output exactly as Your age is: 25.
C++
Need a hint?

Type 25 as input when running the program to see the output.