Piece of crap program...
Moderator: Coders of Rage
Piece of crap program...
Yea I got a book of c++ in 24 hours, and i installed the programs on the cd that came with it (DJGPP compiler, Dev-C++ IDE, and Cygnus Insight debugger). I tried running the simple "hello world" program just to check it out, and when i clicked compile and run, the "hello world" program would open but then close all within a split second. Any tips as to what I can do to keep this from happening?
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Yeah, dude. Everybody has that exact same problem .
Okay, I'm going to assume your sample program looked something like this:
Actually, the program did work. All that this says to do is say "Hello World" and exit. That flash is it saying your hello world. It is just really quick.
To stop it from dieing so fast like that, you would do something like this, and don't worry about what it means for now, your book will explain later.
Okay, I'm going to assume your sample program looked something like this:
Code: Select all
#include <iostream>
int main() {
cout >> "Hello World";
return 0;
}
To stop it from dieing so fast like that, you would do something like this, and don't worry about what it means for now, your book will explain later.
Code: Select all
#include <iostream>
int main() {
int dumby_variable;
cout >> "Hello World";
cin << dumby_variable;
return 0;
}
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
He just told me on AIM that he was using C, not C++.
Also, the reason that it doesn't just close out on you at school is because Metroworks Codewarrior does this step for you and Dev-C++/VisualC++ doesn't.
Your code would look like this (doing this in typical Mrs. Rountree style because I think you have her):
Now, we do the equivalent of what I did in C++ earlier. We are just getting user input before going to the next step (which is exitting the program in this case).
Basically, it won't exit until you push enter.
Also, the reason that it doesn't just close out on you at school is because Metroworks Codewarrior does this step for you and Dev-C++/VisualC++ doesn't.
Your code would look like this (doing this in typical Mrs. Rountree style because I think you have her):
Code: Select all
#include <stdio.h>
int main(void)
{
printf("Hello World");
return 0;
}
Basically, it won't exit until you push enter.
Code: Select all
#include <stdio.h>
int main(void)
{
int dumby_variable;
printf("Hello World");
scanf("%d", dumby_variable);
return 0;
}
Last edited by Falco Girgis on Sun Dec 12, 2004 9:46 am, edited 1 time in total.