Short C++ tutorial ( very short )
Ok this is a very short tutorials on C++, even though i'm only into Arrays right now, I feel I can share my knowledge a tad.
Ok, We will learn how to use a "function" to output text to the monitor.
It can also output
intergers " int " ( -1, -2, -3, -- 1, 2, 3).
float "float" (decimal numbers. 1.0, 2.0, 3.0)
characters "char" ( a, b, c, d, e, f "you call this string too")
and
Doubles " double " These are Floats but with more space.
The stuff in the " " is how you word declare varibales.
Ok, so you want to know how to declare a variable.
varibale, basically a way of allocating memory.
#include <iostream.h> //this is a comment
// ^ don't worry about this yet.
int main() // don't worry about this yet, just studying output.
{ // this tells the complier where the program begins.
char a=A; // declaring the varibale and giveing it a value of A
// always end a statement with a sei-colon ";"
int b = 1; /*declaring the variable b and assigning 1 as it's variable*/
/* This is another form of comments, C style. */
float c = 3.5; // Declaring c and assigning the value of 3.5 to it.
double d=3.1452698 /* declaring the variable d and assigning the value of 3.1452698 to it*/
cout << a << endl; //outputs the value of a to the screen
cout << b << endl; //outputs the value of b to the screen
cout << c << endl; // output the value of c ot he screen
cout << d << endl; //outputs the value of d to the screen
return 0; // terminates the program
} //closing brace
Ok since that looks crowded i'll type the program out without comments. so it looks better
#include <iostream.h>
int main()
{
char a =A;
int b = 1;
float c = 3.5;
double d = 3.1452698;
cout << a << endl;
cout << b << endl;
cout << c << endl;
cout << d<< endl;
return 0;
}
You can have as many whitespaces as you want in C++ ( whitespaces = spaces )
Anyone can add on tot his tutorial. If you want me to add on, reply to this. thanks alot.
C++ tutorial expansion.. Input
Ok, since you should have a basic understanding of Outpu, and got bored with it by now. I will go over basic input.
Bare with me here, I'm busying learning this language and TCP/IP ( and learning more about linux )..
Ok
I gope you remember the comment "//" "/* .... */" . If not look back on them.
#include <iostream.h> // don't worry about this yet.
int main() // or this, lol
{ // opening brace
int a; // our variable that we shall use
cout << " Enter a number to be shown on the screen : \t";
/* the "\t" means TAB, just like "\n" means new line */
cin >> a; // this ask for input by you, to set the value of a
/* notic the differenc between the cout "<<" and the cin ">>", << directs the message to output, and >> recieves the input by you. If i'm wrong onthis please correct me. But it isn't that important as long as you keep them right, and not mix them up */
cout << a << endl; // outputs the value of a
return 0;
} // end of program
remember to end all statements with a semi-colon " ; "
Now I will write the code out with no comments.
#include <iostream.h>
int main()
{
int a;
cout << "Enter a number to be shown on the screen : \t";
cin >> a;
cout << a << endl;
return 0;
}
ok well maybe this will help you all. I must go back to my learning now. If you all would still like some more tutorials, reply.
And remmeber, anyone can add on to this.
Later
MR