Ok, well hello everyone! I just created my account this morning, so you are honored with reading my first ever post on this forum! I bet you are all excited! My name is Colin, and I'm a poor speller, for that I apologize.
I used to program back in High School, 6 or so years ago. Turing, and Visual Basic. For whatever reason, I got interested in trying to learn C++ a couple days ago, so I found the tutorial on cprogramming.com, grabbed Bloodshed dev-c++ 4 and I hit the ground running!
Here is the program I'm working on right now, just to entertain me.
The program is still in its beginnings, but anyway. The problem is this. when I run the program it runs fine. All the dialog shows up and it asks for your name. you then enter your name and when you press enter, it flashes the text after but then promptly closes the program. I just don't understand why the line cin.get(); doesn't catch the program and make it wait. I was under the impression that, that is what it did.Code:#include <iostream> using namespace std; char usrName; // stores the users name int usrAge; // stores the users age int main() // the main important bit { cout<<"Hello! My name is CompColin!\n"; cout<<"I am a computer based personality designed by Colin Gilbert\n"; cout<<"to entertain the really bored and/or lonely.\n"; cout<<"Also I demonstrate my creatores superior intelect!\n\n"; cout<<"Obviously I will need to get to know you better in order to\n"; cout<<"entertain you good and proper like I said I would!\n"; cout<<"Please, tell me your name!\n"; cin>> usrName; // gets the users name and stores it cin.ignore(); // ignores there enter press cout<<"Ahh! Well thats an alright name! Hello "<< usrName <<" Its nice\n"; cout<<"to meet you!\n"; cin.get(); }
Anyway, I've looked into some of the FAQ's and what not and it seems like there are some ways around this, using different technics that I don't fully understand yet. but! the part I truely don't understand is that this program.
Is taken directly from the tutorial on cprogramming.com and it works just fine when I compile it. And to be honest with you guys, it looks pretty much exactly the same as the one I wrote.Code:#include <iostream> using namespace std; int main() { int thisisanumber; cout<<"Please enter a number: "; cin>> thisisanumber; cin.ignore(); cout<<"You entered: "<< thisisanumber <<"\n"; cin.get(); }
So why does cin.get(); catch the tutorials program, but not my program?
Thanks a lot for any help, and I'm sorry if its a really obvious answer, but I've been looking at it for a few hours now, and its not jumping out at me.



LinkBack URL
About LinkBacks


