I looked at some other questions and I'm too newbish at C++ to know if they applied to my question here..
Basically when show the output of "name", if I type in my full name it only shows the second word. Before, it wasn't even taking anything at all, it just skipped it. I'm confused at the moment for something so seemingly simple. THanks.
#include <iostream>
#include <string>
using namespace std;
int main()
{
double money;
string name;
int age;
// Prompt for age and receive
cout<<"How old are you? ";
cin >> age;
// Prompt for money and receive
cout<<"How much money do you have?";
cin >> money >> endl;
// Prompt for name and receive
cout<<"What's your name?\n\n"<< endl;
getline(cin, name);
// Display all information to user
cout<<"Hello, "<< name <<".";
cout << "You are " << age << " years old";
cout<< " and have $" << money << ".\n";
system("PAUSE");
return 0;
}
getline
and>>
unless you really understand how to handle newlines. In your case, just always usegetline
.cin >> money >> endl;
Does this compile ? I tried here and got tons of errors...