ok first if you want any comments in you program code there are two ways to do this.
first one i will show you is a block comment.
/* This opens the comment
you can have as many lines as you want in a block comment
this is how you close a block comment */
Okay the second way is a line comment
// A line comment can only be in that one line.
CODE
#include <iostream>
// this is to include the input, output stream.
using namespace std
// this is used instead of having to keep writing std::cout
main ()
// this is used to start program
// this is to include the input, output stream.
using namespace std
// this is used instead of having to keep writing std::cout
main ()
// this is used to start program
okay so if we where going to set up are program it would look some what like this.
CODE
/*Name
Date
What the program does*/
#include <iostream>
using namespace std;
main ()
Date
What the program does*/
#include <iostream>
using namespace std;
main ()
What i did there is setting up are program now we want it to do something for teaching purposes i am just going to say print "Hello this is a test of C++".
so what we need is a way to do a console output.
CODE
cout <<
// This is used to say we are outputting to the computer screen.
<< endl;
// This is used to end that line of text or make a space. Note that making a space on a blank line with no code on you would do cout << endl;
// This is used to say we are outputting to the computer screen.
<< endl;
// This is used to end that line of text or make a space. Note that making a space on a blank line with no code on you would do cout << endl;
okay now that we have some way to input the code we need to have "" this is where text goes.
CODE
cout << "Hello this is a test of C++." << endl;
//That would print out Hello this is a test of C++ to the command prompt.
//That would print out Hello this is a test of C++ to the command prompt.
Now that we printed that we need a way to end the code so we would put a return 0;
CODE
return 0;
// This basicly tells the program to end it self after one attempt at the program if it works.
// This basicly tells the program to end it self after one attempt at the program if it works.
if we put that entire code together we get this:
CODE
/*Name
Date
What the program does*/
#include <iostream>
using namespace std;
main ()
{
cout << "Hello this is a test of C++." << endl;
cout << endl;
return 0;
}
Date
What the program does*/
#include <iostream>
using namespace std;
main ()
{
cout << "Hello this is a test of C++." << endl;
cout << endl;
return 0;
}
There you go the most basic stuff of C++
When we get more advance in C++ you can do all sorts of things, you can do math, and make a calculator. We get if statements which is where if a variable does not met what it is should do ie. if (variable <= 5) if it is not equal to or less then 5 it wont say that part of the code. This is something that is needed in games, and if you want to learn PHP i would say learn this first to get the use of if statements.


