I am trying to make a program to ask for their name, and then say "Hello, (their name)!" back. Here's my code so far, the "getchar()" is just so it pauses and I can see the output.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout<<"What is your name?:";
cin>>name;
cout<<"Hello, "<<name<<"!";
getchar();
return 0;
}
This asks me for input, and I input my name, and then the application closes! I don't know why and how to fix it! Please help!
EDIT: Found out how to solve it. Finished code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout<<"What is your name?: ";
cin>>name;
cout<<"Hello, "<<name<<"!\n";
system("PAUSE");
return 0;
}