Variables
First of all you learn that in C++ there are data types, named like int (integer), float (floating numbers) or double (double precision floating numbers). They all differ in how much memory they assign and how the computer works/calc with them. You can create variables in memory like this:
For example, these are variables:
1 2
|
int n; // An integer 'n'
double pi = 3.1415; // A floating point number (here Pi). This variable is initialized.
|
If you do not initialize your vars, they have a random value. So be sure, to set the value to something before you use them.
Functions
If you know more about Variables you can process to functions. Functions can take parameter(s) (which have datatypes) und they can return a value (which datatype you have to declare, too).
You declare functions like this:
|
return_type function_name(datatype1, datatype2); // or more/less parameter...
|
For example:
Declarations of functions tells the compiler what type of values he can expect of your functoins. To
define what function do, do following:
1 2 3 4
|
double square(double x)
{
return(x * x);
}
|
Square takes a parameter typed double x and returns x*x (again a double).
Thats pretty much you need to know about functions. Next topic have to be input/output to console. Google for it, because thats very basic HelloWorld and more. (Hint: look for cout and cin).
If you need more help, feel free to ask.
Maikel