Variable trouble

Hey i recently wrote a program using variables. The program works fine but when compile nd run the program the variable always comes out as "4370436". Here is the program:

#include <iostream>

int main() {
using namespace std;

int x;


cout << "What is your name";
cin >> x;
cout << "hello " << x;

system("pause");
return 0;
}


when i compile and run it this is the result:

What is your name? Dan
hello 4370436Press any key to continue...

Why is the variable not Dan??! Someone please help!!!
hello Dan

Why is the variable not Dan??!

Because you're trying to put text into an int. x should be a std::string instead (found in the <string> header).
Topic archived. No new replies allowed.