Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Simple C++ Coding For Beginners

Joined
Aug 4, 2010
Messages
572
Reaction score
177
I'm just going to make this guide for the fun of it, cause i'm really bored and I also want others to learn the ways of coding so I hope you understand their not complicated were starting from step from 1 - 6 and I'll make more guides for beginners after.

-When I'm explaining which function is ... Please don't say its wrong its my way of saying what it means.

Programs needed, any C++ compiling program, GL.

C++ Made Easy.

-----------------
C++ For Programming
-----------------

Code:
[B][U]Step 1 : Simple Hello World Program.[/U][/B]
#include <iostream> // Include IO Stream Library Files.
using namespace std; // Include Files From Standard Library.
int main() // Main file header, (ALWAYS NEEDED).
{ // BEGIN BRACE BRACKET BRACE = {
cout <<"Hello World!"; // Your Text That You Want Displayed.
<< endl; // To Close The Statement "Cout" or others.
cin.get(); // To Keep Your Written Program on the screen so that you can see what you've written.
} // END BRACE BRACKET = } Must Need when ending a statement, the same goes for { for beginning a statement.

That's the end of Step 1.

Code:
[B][U]Step 2 : Variables & User Input.[/U][/B]
#include <iostream> // Include IO Stream Library Files
using namespace std; // Include Standard library files (cout).
int main() // Main Function header file (Always Needed).
{ // BEGIN BRACE BRACKET
int age; // Variable. Mines is named "age". Always have your semi colen.
cout << "How Old Is WizCoder: "; //The Output question that was asked.
cin >> age; // User Input when guessing your age.
cin.ignore(); // Ignore all characteristics.
cout << "You Entered: " << age <<endl; // Output message of what the input user has entered.
cin.get(); // Keeps your programming on the screen when compiling
} // END BRACE BRACKET.

[B][U]END OF STEP 2.[/U][/B]
[B][U]
Code:
Step 3 : If and Else.[/U][/B]
#include <iostream> // IO Stream Library files.
using namespace std; // Includes Standard Library files.
int main() // Main Function Header File.
{ // BEGIN BRACE BRACKET.
    int age; // My Variable Name "age".
    cout <<"How old Is WizCoder: "; // Output Question Asked.
    cin >> age; // User input of guessing your age.
    cin.ignore(); // Ignore all characteristics.
    
    if ( age == 14 ) { // If, age = 14, then your correct.
         cout << "Correct";
         } // End Brace BRACKET.
    else if ( age == 13 ) { // else if, age = 13 your close, this can be added to by copying the exact code and pasting but change the number.
         cout << "Nice try, But your close ";
         }
    else { // For All other numbers, that you haven't included will get the message below.
    cout << "Your Totally wrong, try again.";
}
cin.get(); // Displays your coding on the screen instead of flashing. (Always include this at the bottom of your coding.)
} // END BRACE BRACKET.

[B][U]END OF STEP 3.[/U][/B]
Code:
Step 4 : Loops.
#include <iostream> // Include IO Stream Library Files.
using namespace std; // Include Standard Library Files.
int main() // Main Function Header File ( Always Needed.)
{ // BEGIN BRACE BRACKET.
    int x; // Variable name = "x" but you can change.
    for (int x = 0; x < 10; x ++ ) { // Loop settings, int x = 0; x Less Than 10; x ++ ), Displays The Message Numbers 10 times, but in C++ coding 1 = 0, and 2  = 1 Try to understand by playing around with this.
    cout << x <<endl; // Displays your "x" variable according to above.
} // End BRACE BRACKET.
cin.get(); // Keeps your programming message displayed on the screen.
} // END BRACE BRACKET.

[B][U]END OF STEP 4.[/U][/B]
[B][U]
Code:
Step 5 : Things You Should Understand From Now.[/U][/B]
Here are the relational operators, as they are known, along with examples: 
>     greater than              5 > 4 is TRUE
<     less than                 4 < 5 is TRUE
>=    greater than or equal     4 >= 4 is TRUE
<=    less than or equal        3 <= 4 is TRUE
==    equal to                  5 == 5 is TRUE
!=    not equal to              5 != 4 is TRUE

Comment Lines Adding Your Comments For Instructions Readers.
*/ (Comment You want To say) /*
*/ Means Opening Comment, /* Means your finish your comment.

OR 

// = Opening your comment when you want to state something.

And Signs Important !
So Sometimes you can't use the word "And" or type & when you want to include another word. With C++ its mandatory to use the double signs "||" To use that hold Shift + the key on the left of <-- Sign.

[B][U]END OF STEP 5.[/U][/B]

Code:
[B][U]Step 6 : Functions.[/U][/B]
#include <iostream> // Include IO Stream Library Files.
using namespace std; // Include Standard Library files.
int mult ( int x, int y ); // Function Variable That you want to get multiplied " int x, int y" You can name "x" & "y" to whatever you want.
int main() // Main Function Header File (Always Needed.)
{ // BEGIN BRACE BRACKET.
    int x; // Interger Variable "x" you can change name.
    int y; // Interger Variable "y" you can change name.
    cout <<"Enter what numbers you want to be multiplied: "; //Your Question That your giving.
    cin >> x >> y; // User input directing according to question sent.
    cout << "The Answer to your following question is : " << mult ( x,y ); // Output of the users "C In" input that he has written.
    cin.ignore(); // Ignore all characteristics.
    cin.get(); // Keeps your message( coding ) displayed on the screen.)
} // Close Brace BRACKET.
    int mult ( int x, int y)  // Interger that you wanted to be multiplied, look above at line 3 their the same.
    { // BEGIN BRACE BRACKET.
        return x * y; // Showing The end value x * y. * = Times = X.
        
} // END BRACE BRACKET.


--All Codes were tested before written, thanks for reading if you did.:lol:
 
Last edited:
wat
Loyal Member
Joined
Dec 27, 2007
Messages
369
Reaction score
7
You should put everything in CODE tags, I can really read anything. x.x
 
Mythic Archon
Joined
Apr 8, 2007
Messages
759
Reaction score
21
OP doesn't know what programming is so OP shouldn't try learning it to others.

Explain what the code does and not just what happens on the monitor. It's like you just experiment away without using theory at all.
 
Kingdom of Shadows
Loyal Member
Joined
Jul 13, 2007
Messages
923
Reaction score
320
but in C++ coding 1 = 0, and 2 = 1
This can be misunderstood.
0->9 = 10 numbers, better you say to set the limit value at limit+1 for ex:
Code:
for(int i = 1; i < (10+1); i++){}
or the counting starts from 0 not from 1 or something more logically.
Here
*/ (Comment You want To say) /*
*/ Means Opening Comment, /* Means your finish your comment.
I think you mean
/* (Comment You want To say) */
Good luck with further examples!

Oh, as the ppl above me said use "
Code:
" tags for better look of your thread.
 
Elite Diviner
Joined
Jun 14, 2007
Messages
440
Reaction score
10
Ok just some thought since there are some basic misconceptions there.
I'm writing this since, even if it's YOUR way, it coud lead C++ beginners in WRONG C++ logic or practice.


On your Step1:
-> namespace isn't somekind of "Include Files From Standard Library", it should be used to solve name conflicts since you can have two functions with the same name in two different namespace:
Code:
namespace a
{
    void test1()
    {
    }
}
namespace b
{
    void test1()
    {
    }
}
a::test1();
b::test1();
Now a lot of people are writing "using namespace std" to simply tell to try and use all functions from the "std" namespace. So instead of doing "std::cout" you can simply write "cout".
This lazyness can cause some problems if you have several namespaces in your project and you aren't careful with function names.

Instead of doing a whole "using namespace std" you could only "ease" some parts (here only cout and endl):
Code:
#include <iostream>

using std::cout;
using std::endl;

int main()
{    
    cout << "hello" << endl;
}


On your step 2:
-> cin.ignore(); does not "ignore", it clears the keyboard buffer,
-> cin.get(); you could also use system("pause") but well, not a big deal,


On your step 4:
-> why declare two times your "x" variable? Once in "int x" and once in the "for" loop?, That could lead to confusion since the previous value of "x" wouldn't be used in the for...
-> you tell your loop to take values from 0 to 9 that's why there are 10 displays (x=0 to x=9).
-> you could use ++x rather than x++ another thread talks about it better than I would be,


On your step 5:
-> actually like someone else told in the thread, you go it backwards. It's not what you wrote for a zone comment:
Code:
*/ (Comment You want To say) /*
But:
Code:
/* (Comment You want To say) */


Careful about the logical operators:
-> && and || are the logical operators, meaning "(true || false)" would return true since || is OR "boolean test". && beeing AND.
Though | and & do exist and those are bitwise operators ( ).
 
Newbie Spellweaver
Joined
Nov 2, 2009
Messages
54
Reaction score
21
Ugh I only know basic C++, but well unless what I learnt since the very beginning is wrong:

1- int main() isn't a "header file", it's a function
2- using namespace std; doesn't include anything
3- comments don't start with */ and end with /*, it's the opposite
4- making a function that will return x*y doesn't make any sense
5- a function isn't a variable
6- main() isn't ALWAYS NEEDED, you can use another name it's just some compiler settings
7- cout doesn't come from "using namespace std" but from the "include <iostream>" preprocessor directive
8- endl doesn't "close the statement", it's just an alias for "\n" or "\r\n" depending on what your system is
9- including another word is called concatenation and can be done by using string and operator+
10- you don't need to comment every semicolon, parenthesis or bracket your write
11- please put everything in CODE tags cause it hurts our eyes


So Sometimes you can't use the word "And" or type & when you want to include another word. With C++ its mandatory to use the double signs "||" To use that hold Shift + the key on the left of <-- Sign.
According from this sentence I guess you coded in VB before, proof that "too simple" languages make people ignore how things actually work
 
Newbie Spellweaver
Joined
Sep 16, 2008
Messages
6
Reaction score
1
This is literally the worst c++ guide I've ever read.
I hope no beginner inspired to learn c++ reads this.
 
Newbie Spellweaver
Joined
Aug 5, 2006
Messages
16
Reaction score
0
I really like the tutorial you made for the newbies here but I personally think its kinda messy and hard on the eyes...

just my opinion..words are cluttered up.
 
Back
Top