I have this code and whenever I enter a name that is a single word, everything works correctly. However! Whenever I enter a first and last name,
e.g. "Joe Bloggs"
The console stores the second word "Bloggs" as the second piece of data and skips the next cout and cin.
Why is this?! Here is my code!
(Yes I know that age should be an int, but it's easier to see what I mean if it's a string.)
#include <iostream>
#include <string>
usingnamespace std;
int main(){
string name; //Defines the string name
cout<< "Hello! What's your name? "; //Prints message to screen
cin>>name; //Stores user inputted data into variable name
string age;
cout<<endl<<"Hi "<<name<<" how old are you? "; //Prints message and variable value to screen
cin>>age;
cout<<endl<<"So, "<<name<<" you are "<<age<<" years old."<<endl;
system("PAUSE"); //Press any key to continue...
return(0);
}