Piece of crap program...

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
unasmer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 22
Joined: Wed Nov 17, 2004 9:16 am
Location: Madison, AL
Contact:

Piece of crap program...

Post by unasmer »

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?
Image
User avatar
Falco Girgis
Elysian Shadows Team
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:

Post by Falco Girgis »

Yeah, dude. Everybody has that exact same problem ;).

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;
}
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.

Code: Select all

#include <iostream>

int main() {
     int dumby_variable;
   
     cout >> "Hello World";
     cin << dumby_variable;
     return 0;
}
User avatar
Falco Girgis
Elysian Shadows Team
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:

Post by Falco Girgis »

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):

Code: Select all

#include <stdio.h>

int main(void)
{
    printf("Hello World");
    return 0;
}
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.

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.
unasmer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 22
Joined: Wed Nov 17, 2004 9:16 am
Location: Madison, AL
Contact:

Post by unasmer »

dude thanks falco
Image
Post Reply