Answer to Question #77710 in C++ for Erik

Question #77710
When running the program, remember to press the Enter key after typing the last word of the input line.

•• P1.2Write a program that prints out a message “Hello, my name is Hal!” Then, on a new line, the program should print the message “What is your namejust use the following lines of code:

string user_name;

getline(cin, user_name);

Finally, the program should print the message “Hello, user name. I am glad to meet you!” To print the user name, simply use

cout << user_name;
you must place the line

#include <string>

before the main function.

Here is a typical program run. The user input is printed in color.

Hello, my name is Hal!

What is your name?

Dave

Hello, Dave. I am glad to meet you!
1
Expert's answer
2018-06-01T04:54:00-0400
#include <iostream>
#include <string>

int main()
{
std::string user_name;;
std::cout << "Hello, my name is Hal!"<<std::endl;
std::cout <<"What is your name?"<<std::endl;;
getline(std::cin, user_name);
std::cout << "Hello, "<<user_name<<". I am glad to meet you!";

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS