• Log in or sign up for an account here: https://www.sythe.org/login

Basics of C++ - WIP

Raid500

Forum Addict
Joined
Feb 11, 2007
Sythe Gold
0
Messages
592
Raid's C++ Tutorial WORK IN PROGRESS

Hey everyone, I like c++ very much, it's 1 of my favorite languages to use because of the capabilities with it.C++ is a lot like c and java. In this guide I will explain a lot of the basic things of c++ and hopefully by the time you read the whole guide, you will have learned something.

Chapter 1: Compiler
Chapter 1.1: C++ Compiler
Well in order to compile and run your files made in c++ you will need to get a compiler. I would recommend getting Dev-C++. You can of course try many different compilers and see how you like each 1, I'm just giving you the 1 I use.

Chapter 1.2: Getting to know your compiler
There are a few buttons you will need to know in order to use your compiler. Locate your compile button, run button, save button, and new button. Once you know where those are your set.



Chapter 2: Basics
Chapter 2.1: #include (Header)
Whenever you see #include <SOMETHING> it is telling the compiler to use the declaration from that certain file. The most common you will see is #include <iostream>. For most math programs (calculators with trig functions and square roots) #include <math.h> and for most windows programs (Like programs that search computers ie virus scanners) #include <windows.h>

Chapter 2.2: Cout and cin
The cout statement is what you put before you would like something to be displayed when you run your program. Look at the following bit of code: (Note: this is just a small code it will not work if put into a compiler)

<< is output this(this means whatever is after it)
>> is input this(this means whatever you type in)

Code:
int a;
cout << "What is 1+1?" << endl;
cin >> a;
if(a==2)
cout << "Correct!" << endl;
if(a!=2)
cout << "Sorry you're wrong :(" << endl;

Line 1: int a This is where the integer would be stored, once it is said in the program, the compiler will remember what you said.
Line 2: Cout and endl Cout is just what the compiler displays, you must have << after cout. the endl is just something to make the program look nicer (the spacing)
Line 3: Cin is what you will be inputting and making the compiler save.
Rest of the lines: If statement, a lot like java, if something is true, then this will happen, if not then this will happen or nothing will happen.

Chapter 2.3: Operators
Operators are pretty basic and most are the same. Java, c++, and php operators are all the same. The only ones that people may have problems with are % (Modulo), which I don't even know why you would use and that's why I'm not even going to explain it, if you are interested in learning it I suggest googling it.
&&: You can use this to say if 2 things are true (or false) to say that.
Example:

Code:
cout << "What are the square roots of 9?";
cin >> x;
if(x==3 && -3)
cout << "TRUE!";

||: This is the or operator you can say if this OR this happens then this will (or won't) happen
Example:

Code:
cout << "Who is cool?";
cin >> x;
if(x==Raid)
cout << "TRUE!";

Chapter 2.4: Arrays - 7/31/09
Arrays are similar to ints, but holds more data.

Code:
int runetrinity[3] = { 1, 2, 3 }; //3 in the array
cout << runetrinity[2]; //prints the 2nd number in the array.

You can add mathematical things to arrays also, like..
Code:
int runetrinity [2][3]; //multiply the 2nd and 3rd values in the array runetrinity
int runtrinity [6]; //the result of the above

Chapter 2.5: If Conditional - 7/31/09
As you saw above I used a if statement which is the same as a lot of other languages. In normal words it's like if this happens then this will happen otherwise this happens, kinda confusing so lets look at an example.

Code:
if(raid==online) //if I am online
cout << "Raid is online!"; //output will be this
else //otherwise
cout << "Raid is offline :("; //output will be this

Else if is used for more than 1 thing, not sure how to put this lol
Code:
if(raidspost > 100) //if my posts are greater than 100
cout << "Very nice!"; //this will show up
else if(raidspost < 100) //my posts are less than 100
cout << "noob !!"; //i is nub :(

Work In Progress



Enjoy,
Raid




WILL BE UPDATED PROBABLY WILL TAKE A WHILE FOR THE WHOLE GUIDE!


Note: If you find any errors report them to me :)
 
Wow, thanks, like the way you set it out, a joy to read. So far I'd say 6/10 because I think you need to go further in depth.

Good luck finishing it!
 
An array can old any data type, not just ints like this implies.
 
Runescape Gamblingrunescape gambling
Back
Top