0
0
C++programming~15 mins

Input and output using cin and cout in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Input and output using cin and cout
📖 Scenario: You are creating a simple program that asks a user for their name and age, then shows a greeting message with that information.
🎯 Goal: Build a program that reads a user's name and age using cin and then prints a greeting message using cout.
📋 What You'll Learn
Use string to store the user's name
Use int to store the user's age
Use cin to get input from the user
Use cout to display the greeting message
💡 Why This Matters
🌍 Real World
Getting input from users and showing messages is the first step in making interactive programs like games, calculators, or forms.
💼 Career
Understanding basic input and output is essential for any programming job because it helps you communicate with users and test your programs.
Progress0 / 4 steps
1
Create variables for name and age
Create a string variable called name and an int variable called age.
C++
Need a hint?

Use string name; and int age; inside main().

2
Read user input for name and age
Use cin to read the user's name into name and the user's age into age.
C++
Need a hint?

Use cin >> name >> age; to read both values.

3
Print a greeting message
Use cout to print the message: Hello, <name>! You are <age> years old. Use the variables name and age in the message.
C++
Need a hint?

Use cout << "Hello, " << name << "! You are " << age << " years old." << endl;.

4
Run the program and see the output
Run the program and enter Alice for the name and 30 for the age. The program should print: Hello, Alice! You are 30 years old.
C++
Need a hint?

Type Alice then 30 when the program asks for input.