![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Newbie
Join Date: May 2006
Posts: 7
Rep Power: 0
![]() |
Need help getting started
Okay, I just started a tutorial online, http://www.cprogramming.com. I started it, and compiled and ran. Then nothing happened. I used the same code they used. I don't understand why nothing is happening, I would expect some sort of window to pop up or something. Here's the code so you don't have to go look for it:
Quote:
|
|
|
|
|
|
|
#2 |
|
Programmer
|
what compiler do you use?
|
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Please read the "How to Post a Question" thread. Information is key; you need to think about it. Also, may as well read the forum's faq/rules while you're at it, just for future reference. Having a window appear only long enough to get a flash of it is perfectly normal, if the window belongs to the app. If the window belongs to YOU (because you opened a cmd window and launched your program from there), then it will persist. This is an exceedingly common question and has been answered several times on the forum (which is why we have a search button, to reduce the pain of repeating ourselves). At any rate, the quick solution, IF that's the problem (your informative description falls very short), is to ask for user input at the very end. That has the effect of keeping your program from finishing (and closing its window) before your eyeballs can glom onto things.
Read those thangys. Your operating system, platform, exact error messages, succinct description, are almost ALWAYS needed. We had a mind reader but he was taxed once too often and is now in the looney bin.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Professional Programmer
|
Besides all of those things that DaWei said, change
return 1; return 0;
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#5 |
|
Programmer
|
If you use the devc++ compiler, add the folowing code at the end of program, instead of return 1:
char response; cin>>response; and that should do it |
|
|
|
|
|
#6 | |
|
Professional Programmer
|
hervens48: cin.get(); waits for user to press enter before continuing, which is basically the same thing you're telling him to do. Also, you wouldn't replace return 1; with this code. It's a bad habbit to leave out the termination of the program properly.
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
There's little point wasting a variable, 'response', when you're going to deep-six the input. The only purpose of the input is to make the program wait for a user signal. While a C++ compiler should provide a return for you, if you can't be sure (about your compiler and its compliance), how much does it cost to type, "return 0".
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#8 |
|
Newbie
Join Date: May 2006
Posts: 7
Rep Power: 0
![]() |
I do use Dev-C++ complier. Sorry, I was going to put that in, but I got distracted from the computer and forgot to add it, sorry. I tried replacing return 1; with what hervens said, same thing. I have the cin.get() on there, so I don't understand why a window doesn't pop up or whatever? When I go to the exe file, I double click on it, and the waiting cursor appears for like .2 seconds. Does this mean it is working, its just going on and off the screen too fast for eyes to pick up.
|
|
|
|
|
|
#9 |
|
Hobbyist
Join Date: Sep 2005
Posts: 266
Rep Power: 4
![]() |
Try clearing the stream by using 'cin.clear();' before 'cin.get();'.
EDIT: Make that: cin.sync(); ![]() |
|
|
|
|
|
#10 |
|
Newbie
Join Date: May 2006
Posts: 7
Rep Power: 0
![]() |
i tried both the the cin.clear and cin.sync, and neither worked. They both did the same thing, flash of waiting cursor then back to the normal pointer cursor.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|