Beginning of C++
2010-11-05 @ 16:41:50
As i said i start this tutorial.
First i want to tell i dont have much knowledge about it. But its my blog so i will write here what ever i want :P.
To program i prefer a Dev-C++, its simply freeware program to compile our algoritms.

First we need to declare library what we will use.
#include<cstdlib>
#include<iostream>

Next we can use:
using namespace std;
Its not neccesary. Why we use it i will explain later.

Now we open a main function where we will create our program
int main()
{
int number,tab[10];
Now we declare a variable(zmienna) "number" and a board(tablica) "tab".
Int mean here that we will using a numbers.
WARNING: apostrophe(';') is really importat here. Its points where our function end.


cout<<"Jakiś tekst, np. wprowadź liczbe: ";

cout funstion mean every thing what u want to display in console. If it a Text u use "", if its a one mark u can put it in '', and a name of variable we write with nothing.

If we wont used a "using namespase std" at the beginnig we had to write it like that: "std::cout<<..." and it would took much more time and energy


cin>>number

Here we inscribing some number to our program.

tab[10] mean we have 100 variable called tab. We can use it writing tab[0], tab[1], tab[2],...,tab[9]. Important thing is that u start count all boards from 0.

Always at end put:
system("PAUSE");
return EXIT_SUCCESS;
to end main function
}

If u want write some comments in your program put it behind two slash //Your text.
Its helpfull to remind what u done.


Sample of some program:
Silnia(n!):

#include<cstdlib>
#include<iostream>

using namespace std;

int main()
{
int n,a;
cout<<"Silnia z: ";
cin>>n;
for(a=n-1;a>0;a--){
n*=a;
}
cout<<"Wynosi: "<<n<<'\n';
system("PAUSE");
return EXIT_SUCCESS;
}

I used here
loop for. Its mean: a=n-1; do instructions in {...} science a>0, if a<=0 end loop;subtract 1 from a.
'\n' mean: end line, go to secound line. U can use endl to to do that.
'*=a' mean x=x*a
Comments

No comments

Add comment

Your nick:




 przepisz poprawnie kod

kod z obrazka:


  
This is english blog. User writes in english. If you would like to have blog like this, you can register your own for free.
Register your own english blog
Język angielski matura z angielskiego Gramatyka angielska