C++: Greet someone

Read a name and print a greeting.

What to build

A program that reads one word and uses it in two lines.

Requirements

  • Read one word.
  • Print Hello, NAME! and then Welcome to C++..

Input

One word.

Output

Two lines.

Constraints

The word has from 1 to 50 letters.

Example

Input:

Mitu

Output:

Hello, Mitu!
Welcome to C++.

Why it works

cin fills the variable, and cout prints it in the middle of the fixed text.

Examples

Example 1 · Input
Mitu
Expected output
Hello, Mitu!
Welcome to C++.
Example 2 · Input
Rahim
Expected output
Hello, Rahim!
Welcome to C++.

Hints

Hint 1

Read a word with cin >> name.

Hint 2

Chain the pieces with <<.

Solution

Show one correct solution (try it yourself first)
#include <iostream>
#include <string>
using namespace std;

int main() {
    string name;
    cin >> name;
    cout << "Hello, " << name << "!" << endl;
    cout << "Welcome to C++." << endl;
    return 0;
}

Lesson: Your first C++ program →