Ultimate Shinobi : A Naruto RPG
We've moved locations please join us at our new location. www.ultimateshinobi.getgoo.us
Ultimate Shinobi : A Naruto RPG
We've moved locations please join us at our new location. www.ultimateshinobi.getgoo.us
Ultimate Shinobi : A Naruto RPG
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Ultimate Shinobi : A Naruto RPG

JOIN WWW.ULTIMATESHINOBI.GETGOO.US
 
HomeLatest imagesSearchRegisterLog in

 

 A couple of C++ programming basics.

Go down 
+3
Ichi-Kun
Blaize
Absolute Greed.
7 posters
AuthorMessage
Absolute Greed.
Leaf Jounin
Leaf Jounin
Absolute Greed.



A couple of C++ programming basics. Empty
PostSubject: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyWed Dec 02, 2009 12:23 pm

C++ PROGRAMMING INTRO


Alrighty, I'm gonna break down a program I wrote, and explain a few details of C++ . Hopefully, when you're done reading this, you'll be able to make you're own little programs.

Before you even start learning, you're going to a compiler and linker. An all-in-one program is the best. I would suggest DEV C++ . Unless you wanna spend a couple hundred of dollars on Microsoft Visual Studio. DEV C++ can be found at Bloodshed.net. To start a new project, click Fil => New => Source File

You should get a blank text entry screen. Thats where the code is gonna go. After you input all of the code in your program, you're gonna go to Execute=>Compile. If you don't get any error messages(I say any, but you may get some that don't interrupt the program from being compiled), click Execute=>Run.

Now, first, the code

Code:

#include
#include 
#include

int main()
{
 int integer1;
 int integer2;
 
 cout <<"Use this program to add two integers together\n";
 system("PAUSE");
 cout <<"Input number 1\n";
 cin >> integer1;
 cout <<"Input number 2\n";
 cin >> integer2;
 cout << "The answer is:" <<< "\n";
 system("PAUSE");
 return 0;
}

Now, this code results in the command prompt popping up. It tells me that "this program is used to add two integers together" and that I should then press any key to continue. After that, It asks me to enter the first number. I enter that and it asks me to enter the second number. When I press enter this time, It will say "The Answer is:" and display the answer. It'll say press any key to continue, and when you hit a key, the program will close.

Simple right? Actually, yes. I'll break it down Very Happy

Code:

#include
#include 
#include 

These are declaring certain syntax forms you'll be using. In Laymens terms, the computer needs to know where to find some of the things you are saying.

Code:

int main()
This is your standard int main(). no capitals, and only one space between int and main. This is declaring that you're about to write out a function for your program.

Code:

{
This is declaring that you're starting to write in the function here.
Code:
}
Easily enough, this means you're done writing the function of the program.

Code:

 int integer1;
 int integer2;
This is where we Declare the variables that we'll be using in the program. "integer1" represents the first number we will be inputting, and likewise "integer2" represents the second number. It is important, organizationally, to declare the variables at the top of the program. It makes everything a lot easier. At the end of these statements are a semi colon. you will almost always put a semi colon on the end of your statements, though a few exceptions are the "#include" statements at the top, as well as "int main()".

Code:

cout <<"Use this program to add two integers together\n";
cout is read like "see-out". cout will always have the braces pointed in. I dunno why, it's just how it is. It's basically saying that this is what is displayed on your screen. The text in the quotations is displayed, minus the "\n". the "\n" tells the program to create a new line so it doesn't look all clustered. as would be expected, this statement ends with a semi colon.

Code:

 system("PAUSE");
This statement tells the program to stop for a moment so you can read it. it will display the "Press any key to continue..." text. It's a fairly common statement and ends with a semi colon.

Code:

 cout <<"Input number 1\n";
After pressing any key to continue, this will be displayed as text- "Input number 1". The "\n", if you remember, has the program create a new line. and the statement ends with a semi colon

Code:

 cin >> integer1;
This statement ask for our input from our keyboard. The "cin" is pronounced "See-in". cin statements always has away facing brackets. Again, I dunno why. After the brackets is "integer1". look familiar? it should. It's the same variable that we declared earlier on. This line is basically asking for us to type in what the variable represents. Now, because we used "int", it has to be a number. because it is a math equation, it would be pointless for it to be anything but a number. However, should you need to declare a variable that would require the input of text, you would replace "int" with "char". Also, as a side note the "int" declartion is for integers, or counting numbers, only. if you input decimals, they will be rounded immediately. If you need to input decimals, replace "int" with "float". this statement ends with a semi colon, just like all of them.

Code:

 cout <<"Input number 2\n";
 cin >> integer2;
These are the same as the past two we went over, except your using the second variable that you declared.

Code:

cout << "The answer is:" <<< "\n";
This is by far the most complicated line in our program. It starts with cout, and brackets. Like the earlier examples of cout, it has text inside quotations. however, it then has another set of brackets. why? To continue what is being outputed. after the brackets it says "integer1 integer2". This is telling the computer that it is to take the number that we said represents the first variable (integer1) and add it to ( ) the number we said represents the second variable (integer2). after that, we have more brackets to continue the output. why? Because we need a newline, hence the "\n". Note that the \n was in quotations. It ends with a semi colon.

Code:

 system("PAUSE");
We have another system pause....but why? Well, because without it, the program would shut down so fast after you inputed the value for the second variable that you wouldn't be able to read it.

Code:

return 0;

Return zero tells the program to end.

Code:

{
This tells our compiler that we are done with this function.


Alright! first program succesfully broken down!

Now, in your compiler, it will be displayed a little differently. some things will be different colors, and bolded. Heres what our program would look like in Dev C++
Quote :

#include
#include
#include


int main()
{
int integer1;
int integer2;

cout <<"Use this program to add two integers together\n";
system("PAUSE");
cout <<"Input number 1\n";
cin >> integer1;
cout <<"Input number 2\n";
cin >> integer2;
cout << "The answer is:" <<< "\n";
system("PAUSE");
return 0;
}

Oh, and finally, what the program looks like, after being run in command prompt
A couple of C++ programming basics. Progra10


Last edited by Pat =) on Thu Dec 03, 2009 3:34 am; edited 3 times in total
Back to top Go down
Blaize
Sand Genin
Sand Genin
Blaize



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyWed Dec 02, 2009 12:30 pm

interesting to found out someone knows about c++ other then myself. of course i know just the bits of the basic because of my profession i had to quit learning about programming but i like ur style pat
Back to top Go down
Absolute Greed.
Leaf Jounin
Leaf Jounin
Absolute Greed.



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyWed Dec 02, 2009 12:34 pm

Haha thanks dude, I like to keep it simple, and easy to read.
Back to top Go down
Blaize
Sand Genin
Sand Genin
Blaize



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyWed Dec 02, 2009 12:44 pm

ur welcome pat hope people will use it
Back to top Go down
Absolute Greed.
Leaf Jounin
Leaf Jounin
Absolute Greed.



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyWed Dec 02, 2009 12:54 pm

yeah, pendo asked me to do this. I figured it couldn't hurt lols.
Back to top Go down
Ichi-Kun
C ranked Missing-Ninja
C ranked Missing-Ninja
Ichi-Kun



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyWed Dec 02, 2009 10:33 pm

whhhhhaaat? is this????
Back to top Go down
Renjiro Senju
Leaf Genin
Leaf Genin
Renjiro Senju



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyThu Dec 03, 2009 1:01 am

LOL pat cool use off c++ although you havent specified what #include you used. you should have had three errors come up lol
Back to top Go down
Absolute Greed.
Leaf Jounin
Leaf Jounin
Absolute Greed.



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyThu Dec 03, 2009 2:10 am

Yeah I did have three errors. but they were all insignificant and didn't stop my program from compiling. So I just let them be.
Back to top Go down
Renjiro Senju
Leaf Genin
Leaf Genin
Renjiro Senju



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyThu Dec 03, 2009 2:22 am

LMAO!!! fair enough just thought id give you a heads up just incase you might have wondered (im doing a IT degree with 3 programming modules lol, C, C++, VB.NET, J#, Java, compiler code and a couple bespoke languages for microprocessors)
Back to top Go down
Absolute Greed.
Leaf Jounin
Leaf Jounin
Absolute Greed.



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyThu Dec 03, 2009 2:44 am

Nice. I'm prolly going to college for computer programming. I figure I may as well start now.
Back to top Go down
Travis
Akatsuki
Akatsuki
Travis



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyThu Dec 03, 2009 3:18 am

I'm taking C++ now, next semester Java for me.
Back to top Go down
Absolute Greed.
Leaf Jounin
Leaf Jounin
Absolute Greed.



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyThu Dec 03, 2009 3:31 am

Oh, and renji, nvm, I see what you mean now. I typed them in originally, but the forum seems to have edited them out.. edited again.
Back to top Go down
Absolute Greed.
Leaf Jounin
Leaf Jounin
Absolute Greed.



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyThu Dec 03, 2009 3:39 am

well, those "#incliude"s shouldn't be blank... but I guess the forum doesn't like them?
Back to top Go down
Renjiro Senju
Leaf Genin
Leaf Genin
Renjiro Senju



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyThu Dec 03, 2009 3:40 am

PMSL!!!!!!! Epic Fail Forumotion
Back to top Go down
Kenshiki Naito
Leaf Jounin
Leaf Jounin
Kenshiki Naito



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptySat Dec 05, 2009 2:20 am

I've not seen the code for about a yr or two now, it brings back some memories.
Back to top Go down
DarkChaosPriestess
Leaf Genin
Leaf Genin
DarkChaosPriestess



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptySat Dec 05, 2009 7:07 am

Ah, C++...

I am a Java person, myself. I got a five on my AP Test for JAVA Programming. ;D
Back to top Go down
Blaize
Sand Genin
Sand Genin
Blaize



A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. EmptyMon Dec 07, 2009 6:41 am

DCP IS A G lmfao
Back to top Go down
Sponsored content





A couple of C++ programming basics. Empty
PostSubject: Re: A couple of C++ programming basics.   A couple of C++ programming basics. Empty

Back to top Go down
 
A couple of C++ programming basics.
Back to top 
Page 1 of 1
 Similar topics
-
» Just the basics ( should've been on my app)
» Couple of Jutsu
» headin to grandma's house for a couple of days

Permissions in this forum:You cannot reply to topics in this forum
Ultimate Shinobi : A Naruto RPG :: Social Areas :: General Discussion-
Jump to: