This is my first time ever programming in C++ so please talk me through this step by step. This is my second compilation after the classic Hello World! program and I am running into a problem I cannot figure out.
The code executes just fine but when I run it, it gives me two lines 'at the same time' asking me to enter my first and last name. I want there to be a pause where it asks me for my first name first ... press enter, THEN asks me for my last. Here's the code.
//Programmer:Ace
//This program read and writes first_name
//Such a message is typically called a prompt because it prompts
//the user to take an action
//program written on 04/26/10
#include <iostream>
#include <string>
int main ()
{
//A string variable may be initialized at the point of declaration
std::string myfirst_string=" a message which is typically called a prompt";
std::cout <<"This is "<<myfirst_string <<":\n";
std::cout <<"Please enter your first name (followed by 'enter'):\n";
std::string first_name ; // first_name is a variable of type string
std::cin >> first_name; // read characters into first_name
std:cout <<"Please enter your last name (followed by 'enter'):\n";
std::string last_name; // last_name is a variable of type string
std::cin >> last_name; // read characters into last_name
std::cout <<"Hello, you are "<<first_name<<" " <<last_name<< "!\n";
return 0;
}
Thanks.