ok so because i just can not get enough of C++ i decided that i'll go ahead and make a tutorial. because it's 11:30 pm right this second i'll start now and finnish later so keep comming back i'll continue to add stuff.
also please note that i have a tendancy to ramble... but most of what i say is usefull, so if you lack patience this probably isn't the tut for you.
ok here we go
The Basicsbecause when i frist started C++ (from here on out called cpp) i have never programmed anything in my life...ever. i knew a small amount of html and that was it (make no mistake html is NOT a programming language). so this Tut will assume you know nothing what so ever about cpp or it's syntax (gramatical rules)
cpp started out as a modification on c. it was a programmers joke (thats right programmers make jokes too, they're just never funny) the ++ operator increments a variable by one (don't worry i'll explain all of this operator and variable nonsense later) so it is c + 1 in essence...hahahaha funny right?

on to the code.
the bare bones of a program in c++ is simple and easy to remember (i want you to see it and rememeber it so i'll be posting copious amounts of code)
#include <iostream>
int main()
{
return 0;
} ok right about now you'r probably saying something like "great now what do i do with all that crap" well let me break things down and start from the begining, but write that code down and remember what it looks like.
your first program, just like you're first scar script, will have a purpose. and before you start programming you will want to come up with a problem you want to solve. lets say you want to take two numbers one small in between 1 and 5. and one large between 10 and 100. and then check to see if they go into each other evenly. simple enough right? well yes it is but we can make it even easier by think in simple terms or pseudo code ( this is english made to look like code but really wouldn't do anything but get an idea on paper)
so you come up with this.
ask for numbers
store numbers
divide numbers
check to see if it comes out to be 0
send message upon success
simple right? why yes it is and now you have your plan. but how to implement it you don't know how to do anything or what anything is. well lets start out with getting you familiar with that code i had you write down earlier.
#include <iostream> iostream is a reference that tell the compiler what certain commands mean in this case it tells it about two different commands that i will introduce you to shortly.
int main() ok this is a function declareation. this is your main function, inside of this is where your code will go (we will get into defining your own functions and declaring global variables later but please note that when your programs become more advanced most of your code will not be in the main() loop.) it tells the compiler that this is a function called main and the "int" part tell the compiler that the function will return an integer (i'll tell you what an integer is later on)
{}goes before and after all code in all functions, loops, and if statements
return 0;in cpp all programs must end ant this tells the complier "ok it's time to stop" what it accualy does is returns the 0 or false statement to the compiler so in effect the main function ended up saying "false".
Input and Outputok so while the code i showed you before technically is a program, it doesn't do anything. so now we will learn how to make the program talk.
the std::cout << "" <<; command will tell the compiler to output text or numbers to the command prompt.
the system ("pause"); command will pause the program to make the result it returns readable.
so with those two commands we can move on to the time honored tradition of the Hello World! program
#include <iostream>
int main()
{
std::cout << "Hello World!" <<;
system ("pause");
return 0;
}there you have it the Hello World. as you can see the text go inbetween the quotes ("") and a semi-colon must follow all commands. please note you can continue commands onto two or more lines as almost all cpp compiers ignore white space (tabs, spaces, hard returns, etc.) so the following would work.
#include <iostream>
int main()
{
std::cout << "1111111111111111111
1111122222333333333334444444444" <<;
system ("pause");
return 0;
}now do i recomend that? absolutly not as if you do that all over even i will be unable to read your code. however note that in some cases we want to do this.
ok for now thats it the basics of program setup and output have been covered i will cover variables, input and functions later
Variablesok lets say a variable is a cup... a cup can hold anything right? water, soda, vodka, you name it

. and when your done with the cup you can pour out whatevers in it. or maybe you want to mix the stuff in the cup with apple juice. its the same with variables you can put whatever you want into them and can modify them at anytime with anything. however there are limitations with what you can do with different types of variables. let me list the different types of variables.
integer <----- holds whole numbers only eg. 1, 69, etc. (no decimals) goes from -2,147,483,648 to 2,147,483,647
float <----- holds decimal numbers eg. 12.456, 18.9, 255.12 goes from 1.2e-38 to 3.4e38
bool <----- holds only two different values. true and false (they are the only thing that can be used with bool)
those are the three basic types of variables there are more but we will get into that later. for now the only ones you will need to know are those.
so lets show you how to put those variables to good use
you define a variable by puting the name of the type then the name you wish to call your variable. it can be a single letter or a word ***note your variable names CANNOT contain spaces*** i always make sure i name my variables usefull names so i remember what i was going to do with them later. however you can use single letter variables for now just don't get used to it. lets give you an example of how to declare a variable.
int main()
{
int x = 10;
std::cout << "we made x equal:" << x <<;
system("pause");
return o;
}so as you will see we decalred an integer by saying
int (the variable name here) = (value here);
however say you didn't want to say what the value of the variable was when you defined it. maybe you wanted it do be user defined? i will now introduce you to the cin function (i pronounce it "see-in" but you can call it what ever you want). it's syntax is as follows std::cin << (variable w/o parenthasis) <<; it will stop and take user input from the keyboard. this is very usefull for dynamic scripts that are completely based off of what the user tell the program.
so the following code will allow you to define a variable then have the user decide what he wants to make it (please not that the variable limits apply so if the user enters a number that is of the wrong type or is too big it will return a runtime error please see above
for the table with variable limits)
#include <iostream>
int x;
int main()
{
std::cout << "please enter a integer:" <<;
std::cin << x <<endl;
x = x + 15;
std::cout << "you variable plus 15 is " << x <<;
system("pause");
return 0;
}as you will notice i declared the integer x then inside the main function i allowed the user to give it a value i then added 15 to x then stored it back onto x. then i used the cout function to display the final result. i added a function in there that i didn't explain before endl (or end line) it is added after the << of ither cin or cout.(the semi colon must follow the endl function) this will allow you to make dynamic programs that respond to user input.
If Else and Forok if you have followed me this far and have understood the concepts explained then you may be saying something like well what if i want it to say something if x is equal to 5 but something else if it's not? and the answer is....que drum roll...The If Statement. thats right the if statement can solve all of your branching needs and it come at the low low price of three easy payments of $19.99. no just kidding the if statement is free but it can solve all of your branching needs.
include <iostream>
using namespace std;
int main()
{
int x;
cout << "Please Enter a number between 0 and 20!:"<<;
cin << x <<;
if (x < 10)
{
cout << "Your number: << x << "is less than 10" <<endl;
}
cout << "your number is not less than ten" <<endl;
system("pause");
return 0;that is the basic syntax for a if statement the cout command will only be executed if the variable x is less than ten. if it's not less than ten it wount execute and the message your number is not less than ten will appear.
-Se7eN