Ok, we all know I'm not the best at C++, but I do know a little bit.
I am going to break down the "Hello World" application and explain what each part does.
Here is the way I would code the "Hello World" App.
Ok, the #include part is called the header, you NEED that in every program.
The int main() part tells the computer (or whatever) that this is the main part of the program.
Cout is basically a text thing. Do cout<<" [text] \n";
The \n makes it move to the next line and it is optional to include.
You HAVE to have the ; at the end of every command statement.
cin.get(); - It basically makes a pause. If you don't include that, the program will run, then close within a second. cin.get() waits untill you press "enter" to move on in the code.
After int main() there is a "{".
And at the end there is a "}".
These are called brackets, they tell the computer that there are commands inside of that. After main() to the end is one big command. (It's not that big though, lol.)
There is also commands inside of commands.
Like this:
Ok, theres a bit more explaining to do now...
int number; - It identifys that a variable that is a number (hense the name "number") is going to be said and you would like to store the number that is said.
cin>> number; - That is what stores the number information.
cin.get(); - Waits for them to press enter, remember? I put it there so that they have time to put in their number and press enter to submit it.
if ( number == 6 ) { - means that if the number equals 6, everything after the bracket "{" will happen untill the end bracket "}".
else ( number != 6 ) { - means that if any other number that does not equal 6 is put in, the stuff after the first bracket "{" happens untill the end bracket "}".
Not sure if you need the ( number != 6 ) part, but I put it in to be safe.
Again cin.get(); - Very helpful, makes a pause for the person to read the cout from after they answer. Then when they press enter, the program will close.
Notice the end bracket "}" to the program.
Notes:
This is the stuff I started with.
I am going to break down the "Hello World" application and explain what each part does.
Here is the way I would code the "Hello World" App.
Code:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World!!\n";
cin.get();
}
Ok, the #include part is called the header, you NEED that in every program.
The int main() part tells the computer (or whatever) that this is the main part of the program.
Cout is basically a text thing. Do cout<<" [text] \n";
The \n makes it move to the next line and it is optional to include.
You HAVE to have the ; at the end of every command statement.
cin.get(); - It basically makes a pause. If you don't include that, the program will run, then close within a second. cin.get() waits untill you press "enter" to move on in the code.
After int main() there is a "{".
And at the end there is a "}".
These are called brackets, they tell the computer that there are commands inside of that. After main() to the end is one big command. (It's not that big though, lol.)
There is also commands inside of commands.
Like this:
Code:
#include <iostream>
using namespace std;
int main()
{
int number;
cout<<"What number am I thinking of?\n";
cin>> number;
cin.get();
if ( number == 6 ) {
cout<<"Good, you guessed it right\n";
}
else ( number != 6 ) {
cout<<"Wrong!\n";
}
cin.get();
}
Ok, theres a bit more explaining to do now...
int number; - It identifys that a variable that is a number (hense the name "number") is going to be said and you would like to store the number that is said.
cin>> number; - That is what stores the number information.
cin.get(); - Waits for them to press enter, remember? I put it there so that they have time to put in their number and press enter to submit it.
if ( number == 6 ) { - means that if the number equals 6, everything after the bracket "{" will happen untill the end bracket "}".
else ( number != 6 ) { - means that if any other number that does not equal 6 is put in, the stuff after the first bracket "{" happens untill the end bracket "}".
Not sure if you need the ( number != 6 ) part, but I put it in to be safe.
Again cin.get(); - Very helpful, makes a pause for the person to read the cout from after they answer. Then when they press enter, the program will close.
Notice the end bracket "}" to the program.
Notes:
- cin.get(); waits untill the person presses enter to move on.
- ";" is needed at the end of every command line.
- Make SURE you have a header on every app you make.
- "==" means equals to, "!=" means does not equal.
- When using int [variable]; you can change the int to a char. int stands for integer, meaning any WHOLE number with no decimals. char stands for character, meaning words or letters with no spaces.
![m3m - [C++] Tut by m3m for beginners - RaGEZONE Forums m3m - [C++] Tut by m3m for beginners - RaGEZONE Forums](http://forum.curse-x.com/images/smilies/tongue.gif)
This is the stuff I started with.