0
0
C++programming~15 mins

Multiple input and output in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Multiple Input and Output in C++
📖 Scenario: You are creating a simple program to collect and display information about a book. This is like filling out a form with multiple pieces of information and then showing it back to the user.
🎯 Goal: Build a C++ program that takes multiple inputs from the user (title, author, and year) and then prints them out clearly.
📋 What You'll Learn
Use std::string variables for text inputs
Use int variable for the year
Use std::cin to get inputs
Use std::cout to display outputs
Handle multiple inputs and outputs in a clear format
💡 Why This Matters
🌍 Real World
Collecting and displaying multiple pieces of information is common in programs like forms, surveys, and data entry systems.
💼 Career
Understanding how to handle multiple inputs and outputs is essential for building interactive applications and user interfaces.
Progress0 / 4 steps
1
Create variables for book information
Declare three variables: a std::string called title, a std::string called author, and an int called year.
C++
Need a hint?

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

2
Get input from the user
Use std::cout to ask the user to enter the book's title, author, and year. Then use std::getline(std::cin, title) for the title and author, and std::cin >> year for the year to get the inputs.
C++
Need a hint?

Use std::getline for strings to allow spaces, and std::cin for the integer.

3
Display the collected book information
Use std::cout to print the book's title, author, and year in a clear format. Use multiple std::cout statements or one combined statement.
C++
Need a hint?

Use std::cout with the << operator to print variables and text.

4
Run and display the final output
Run the program and print the book information exactly as shown: first the prompt lines, then the book information with labels Title, Author, and Year each on its own line.
C++
Need a hint?

Make sure your output matches the prompts and labels exactly, including new lines.