Hi everyone today i am going to teach you a very simple program and how it is made. I wont get into anything fancy right now but will teach you how to run a program in the command prompt. 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.
#include <iostream>// this is to include the input, output stream.using namespace std// this is used instead of having to keep writing std::coutmain ()// this is used to start programokay so if we where going to set up are program it would look some what like this. /*NameDateWhat 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. 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;okay now that we have some way to input the code we need to have "" this is where text goes. cout << "Hello this is a test of C++." << endl;//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; return 0;// 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: /*NameDateWhat 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.