Hi all

Any help would be much appreciated.

Im following the about.com tutorial, and one of the exercises says i should make this program;

#include <iostream>
#include <string>
using namespace std;
int main ()
string name;
int ID;
cout<<"enter your name\n";
cin>> name;
cout<<"enter your id\n";
cin>> ID;
cout <<"hello" <<name <<", or should i say" <<ID <<endl;
return 0;

It compiles fine; when I run it, it asks me for my name, and then id, but when i press return it just closes the window.

Ive tried adding in a cin.get() , which resolved the problem with the hello world programme i did, but not this.

I dont understand why it wont display the text afterwards?!?

Help please for my sanity (why dont think work like on the tutorials - did people try out the programmes before putting them on?)

P.S As a an afterfthough what purpose does the endl tag serve? it doesn't seem to make a difference.

12 Years
Discussion Span
Last Post by Simon268

You might also be entering your full name with a space.

Spaces give problems. So you might want to try using cin.getline() instead of just cin?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.