Cpp - Write program to greet user

Requirements

Write a program that asks a user's first and last name.

Display the first name and last name as part of a sentence greeting the user.

Hint

Use std::cin

Demo

#include <iostream>
  
int main()//from  w  w  w . j ava  2 s  .c om
{
    char firstName[40];
    char lastName[40];

    std::cout << "Enter your first name: ";
    std::cin >> firstName;
    std::cout << "\nEnter your last name: ";
    std::cin >> lastName;
    std::cout << "\n";
 
    std::cout << "Hello, " << firstName << " " << lastName << "!";
    std::cout << " You look great. Have you lost weight?\n";

    return 0;
}

Result

Related Exercise