0
0
C++programming~15 mins

Variable declaration and initialization in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Variable declaration and initialization
📖 Scenario: You are creating a simple program to store and display information about a book.
🎯 Goal: Learn how to declare variables and initialize them with values in C++.
📋 What You'll Learn
Declare variables with correct types
Initialize variables with given values
Print the values to the console
💡 Why This Matters
🌍 Real World
Storing and managing information about items like books is common in many software programs.
💼 Career
Understanding how to declare and initialize variables is a fundamental skill for any programming job.
Progress0 / 4 steps
1
Declare variables for book information
Declare a variable called title of type std::string and initialize it with the value "The Great Gatsby".
C++
Need a hint?

Use std::string to declare a text variable and assign the value with =.

2
Declare and initialize more variables
Declare a variable called author of type std::string and initialize it with "F. Scott Fitzgerald". Also declare an int variable called year and initialize it with 1925.
C++
Need a hint?

Use std::string for text and int for whole numbers.

3
Add a variable for price
Declare a variable called price of type double and initialize it with 10.99.
C++
Need a hint?

Use double for decimal numbers.

4
Print all book information
Use std::cout to print the variables title, author, year, and price each on its own line.
C++
Need a hint?

Use std::cout << variable << std::endl; to print each variable on a new line.