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.

The only problem I found was line 16: you have just one colon instead of two after std. Otherwise it worked ok for me with Code::Blocks on Ubuntu.

Woot, it worked! I have no idea how I could have missed that after so many revisions. Programming sure is tricky! I love it.

A little piece of advice: do put all your variable declarations at the beginning of the function
It helps a lot in terms of readability and program maintenance in future.

commented: Agree +28
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.