Cobain Programming

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

User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

I get on MSN sometimes but not that frequently. Try these steps out.... then again, you have a higher version then me so I hope this still works.
  • >Open up Dev-C++
    >Goto 'File' and click 'New Project'
    >Click on 'Console Application' (its like an icon thingy)
    >Make sure the 'c++ project' radio button is selected
    >Click 'OK'
    >Type in "Test Project" into the 'Project Name' box and click 'OK'
    >Save "Test Project" to a new folder that you can easily find
    >A text editor should now replace the grey area in Dev-C++
    >Goto 'Execute' and click 'Compile and Run'
    >Name the file 'Main' and click save
    >Did you see a strange black box flash for an instant?
    >Now erase all that stuff in the editor and paste the below code in.

Code: Select all

#include <stdio.h>
#include <iostream>

//Hey look, this is a comment! Use these to record what you
//were thinking when you code something

//Declaring an Integer
int Number;

//Program execution starts here
int main(int argc, char *argv[])
{
    //Print out this string to the console
    cout << "Woot Woot! It works! Now enter a number foo!\n";

    //Get input from the user
    cin >> Number;

    //Display what the user entered
    cout << "\n\nYou entered the number " << Number;

    cout << "\n\n\n\nEnter another number and this program will quit.";

    //Get more input from the user
    cin >> Number;

    //Return to the Operating System!
    return 0;
}
  • >Goto 'Execute' and click 'Compile and Run'
    >The program should compile and execute with NO errors.
Tell me if that worked.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
cobain
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 45
Joined: Mon Nov 22, 2004 5:37 pm
Location: Tennessee

Post by cobain »

w00t it worked, all the program did was pull up the black box i think called the command console or somethin u nkow on start menu, select run and type in cmd that little black box comes up. thats what happened here it said "press a key" and soon as i did the black box dissappeared :) that what its sposed 2 do? thx alot also
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 »

JS Lemming's program? No, it shouldn't of done that. It should've prompted you for a number, printed it back out, then asked for you to push a key to exit.

If you're using an example from the book where it just returns 0, then yes, that's right.
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 »

Sorry for the split in the topic, but this so didn't have anything to do with programming resources.

Tell me, cobain, why do you want to learn C++? Do you think you'll become some sort of mad-ass l33+ h4><0r? Do you think you can make the next Halo or Half-Life?

Sadly, those are all foolish perceptions. I've seen people think that. People think programming will get them so far. Guess what, it won't. It's time consuming, it is HARD, and you really have to enjoy what you're doing.

It is a very humble and time-consuming practice. You'd be amazed at the complexity of just drawing to one pixel on a screen. If you aren't serious about this, spare yourself your life. Just quit.

If you are, welcome aboard.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

And please use capitalization, punctuation and complete words. Makes you look smarter, and that's never bad. This is a forum, not a chat room -- you have as much time to type as you want, so please use it.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

I don't think discouraging peoples-es is the way to go. I'd rather have more people in the world that at least know what a compiler is then none at all. The thing is, programming isn't really that hard. All you need is a logical train of thought and an understanding of how teh compoots work. Oh, and a little creativity may help too. And a few pilgrimen books. And blaa with blaa with a pich of blaa.
Last edited by JS Lemming on Sun Nov 28, 2004 11:39 am, edited 1 time in total.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

JSL wrote:And blaa with blaa with a pich of blaa.
I had to copy-paste that.

You jerk. :)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
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 »

Are you talking about me? I don't think that allowing people to think falsely is good.

People think "Oh, just learn C++ in a few weeks and I'll make Half-Life 3". Nope!

It's really depressing watching people believe that too.
cobain
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 45
Joined: Mon Nov 22, 2004 5:37 pm
Location: Tennessee

Post by cobain »

I am extermely sorry about my spelling. Is this better? And the reason that i wish to learn C++ is that i would like to know more about comptuers and how they work, i nkow that i will never be able to program even the simplest of games probably and i have no intrest in programming complicated ones anyways. I simply wish to advance my knowledge of comptuers. Should this text just make the command prompt pop up for an instant, just long enough to see it once this code is compiled and run?

int main(int argc, char* argv[])
{
return 0;
}
Do colors matter at all if I am using DEV C++. Some text appears in blue, some green, some red and some black. Once more I tried running JS Lemming's program and it hilighted this line in red with an "X" next to it.
cout << "Woot Woot! It works! Now enter a number foo!\n";
For that i choose compile and run.
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 »

Holy crap, that spelling makes you seem like a whole new person. In that case, cobain, you're learning to program for a great reason. Welcome aboard.

Code: Select all

int main(int argc, char* argv[])
{
return 0;
} 
Yeah, that should just pop the DOS console (or say program has ended depending on your compiler).

Colors? As in like the font in your Dev-C++ environment? Naw, shouldn't matter.

Code: Select all

 cout << "Woot Woot! It works! Now enter a number foo!\n"; 
Hmmmm... I don't see anything wrong with that line. Perhaps you're missing a semicolon or something on the line above? Can you post the whole source?
cobain
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 45
Joined: Mon Nov 22, 2004 5:37 pm
Location: Tennessee

Post by cobain »

Sorry about posting about things all the time, lol (is it ok to say lol? its abbreviating you know) but now i am on chapter two of my book. The program that I copied directly from it's text is as follows:

#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
// Without "using" statement, this would be std::cout
cout << "Hi there!" << endl; // "endl" = next line
return 0;
}

In my book it says the output is supposed to say Hi there! but still the command prompt popped up for 0.02 seconds after i selected compile and run, also the type of file I chose was Console Application. Why isn's it saying "Hi there!"?
cobain
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 45
Joined: Mon Nov 22, 2004 5:37 pm
Location: Tennessee

Post by cobain »

Whole source? Not quite sure what you mean by that but if you mean the whole program, its just the one JS Lemming wrote, which is

Code: Select all

#include <stdio.h> 
#include <iostream> 

//Hey look, this is a comment! Use these to record what you 
//were thinking when you code something 

//Declaring an Integer 
int Number; 

//Program execution starts here 
int main(int argc, char *argv[]) 
{ 
    //Print out this string to the console 
    cout << "Woot Woot! It works! Now enter a number foo!\n"; 

    //Get input from the user 
    cin >> Number; 

    //Display what the user entered 
    cout << "\n\nYou entered the number " << Number; 

    cout << "\n\n\n\nEnter another number and this program will quit."; 

    //Get more input from the user 
    cin >> Number; 

    //Return to the Operating System! 
    return 0; 
}
And at the bottom it hilighted(<--spelling?) line 14 and said this:
`cout' undeclared (first use this function)
It is still quite diffucult for me do depict how many spaces are supposed to be used, especially copying straight from my book. It says nothing about what lines to indent, how many spaces to indent them, or when to put one space between characters and when to put two.
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 »

Don't worry about spaces. The compiler doesn't care. If you don't even want them, don't put them (It's always good to indent things between {} at least a little though).

OH OH OH! I know what's wrong with JSL's program. You need to specify where his cout and cin are.

Just do this:

Code: Select all

#include <stdio.h>
#include <iostream>

//Hey look, this is a comment! Use these to record what you
//were thinking when you code something

//Declaring an Integer
int Number;

//Tell the compiler where cout/cin are.
using namespace std;

//Program execution starts here
int main(int argc, char *argv[])
{
    //Print out this string to the console
    cout << "Woot Woot! It works! Now enter a number foo!\n";

    //Get input from the user
    cin >> Number;

    //Display what the user entered
    cout << "\n\nYou entered the number " << Number;

    cout << "\n\n\n\nEnter another number and this program will quit.";

    //Get more input from the user
    cin >> Number;

    //Return to the Operating System!
    return 0;
} 
I just added using namespace std;. Try that, it should work now. All that line is doing is telling the compiler that you're using the cout (and cin) from the standard library.
cobain
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 45
Joined: Mon Nov 22, 2004 5:37 pm
Location: Tennessee

Post by cobain »

Sorry about posting about things all the time, lol (is it ok to say lol? its abbreviating you know) but now i am on chapter two of my book. The program that I copied directly from it's text is as follows:

#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
// Without "using" statement, this would be std::cout
cout << "Hi there!" << endl; // "endl" = next line
return 0;
}

In my book it says the output is supposed to say Hi there! but still the command prompt popped up for 0.02 seconds after i selected compile and run, also the type of file I chose was Console Application. Why isn's it saying "Hi there!"?
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

CURSE "using namespace std;"

Did that fix it? Heh, I guess version 4 is a weee bit more leiniant (man I really tore up that word). If that didn't fiz the problem, try putting a .h after the iostream include thingy.

Cobain, I guess you can use lol, BUT it is always best to use "bag". Do you know why? Because it stands for Bust-A-Gut. EAT THAT FOOLS!

About the spaces thing.... let me post an example. Which looks better and easier to follow?

Code: Select all

//Returns true if the two rectangles are overlapping
bool RectsOverlap(int x1,int y1,int width1,int height1,int x2,int y2,int width2,int height2) {
if((x1+width1 > x2) && (x1 < x2+width2)) {
if((y1+height1 > y2) && (y1 < y2+height2)) {
return true;
}
}
return false;
}
or

Code: Select all

//Returns true if the two rectangles are overlapping
bool RectsOverlap(int x1,int y1,int width1,int height1,int x2,int y2,int width2,int height2) {
    if((x1+width1 > x2) && (x1 < x2+width2)) {
        if((y1+height1 > y2) && (y1 < y2+height2)) {
            return true;
        }
    }
    return false;
}
Pick number 2 please.

Ok, about the console box flashing for 0.0000000000001th of a second. Tis not your fault. The program simply has no reason to stay in existence. The deed is done. Problem is, the human usually needs to stare at the pretty color monitor for a little longer in order to take everything in. An easy solution? Just put this right before the return 0 thing.

int DumbyVar;
cin >> DumbyVar;

That will keep the console open untill you enter a number.
Do colors matter at all if I am using DEV C++. Some text appears in blue, some green, some red and some black.
Those colors are there just to help you with syntax. If you spell a c++ syntax thing correclty, you get to see the colors. It just keeps stupid mistakes at a min.

Bwuhahaha!!! I just made you copy-paste a random chunk of text. Hey, at least I'm not posting secret binary messages.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Post Reply