0
0
C++programming~15 mins

Basic formatting in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Basic formatting
📖 Scenario: You are creating a simple program to display a person's name and age in a nicely formatted way. This is like writing a friendly introduction card.
🎯 Goal: Build a C++ program that stores a person's name and age, then prints a formatted sentence introducing the person.
📋 What You'll Learn
Create variables to store a person's name and age
Use a helper variable to store a greeting message
Combine the variables into a formatted sentence using std::cout
Print the final formatted sentence
💡 Why This Matters
🌍 Real World
Formatting text output is useful for creating user-friendly messages in console programs, reports, and logs.
💼 Career
Basic formatting skills are essential for software developers to display information clearly and professionally.
Progress0 / 4 steps
1
Create variables for name and age
Create a std::string variable called name and set it to "Alice". Create an int variable called age and set it to 30.
C++
Need a hint?

Use std::string name = "Alice"; and int age = 30; inside main().

2
Add a greeting message variable
Create a std::string variable called greeting and set it to "Hello".
C++
Need a hint?

Use std::string greeting = "Hello"; inside main().

3
Combine variables into a formatted sentence
Use std::cout to print the sentence combining greeting, name, and age in this exact format: Hello, my name is Alice and I am 30 years old.
C++
Need a hint?

Use std::cout << greeting << ", my name is " << name << " and I am " << age << " years old." << std::endl;

4
Print the final formatted sentence
Run the program and ensure it prints exactly: Hello, my name is Alice and I am 30 years old.
C++
Need a hint?

Run the program and check the output matches exactly.