This is more an information post for people that don't know what as example an int is. I will explain this here.
Data Types:
Int: comes from the word Integer and is a variable that can only hold full figures like 1, 56, -8 etc.
Float or Double: these are floating point numbers like 4,6 12,7 the decimals are limited though.
Char: comes from "character" it is a variable used to save only characters such as: K, L, k, l
String: Well a String is basicilly a char array. A string contains more than one character as example full words.
Before we come to the last Data Type, I have to say that a char is always saved with an apostrophe '
as example: 'H' the string uses the " signs so: "hello".
Booleans: Booleans are variables that contain wheither a "true" or "false" value.
Now because we want to connect the variables with eachother we need operators:
arithmetic operators
compare operators
logic operators
Non of them are hard when you don't understand them the first time read it another time. Operators and algos are important for coding(algorythms are excluded here) as well as sortalgorymths such as Insertionsort(picks a random number out of a list and then sorts it after that), Mergesort(list gets divided in two different lists and always divided again and merged at the end) and bubblesort(I have no idea).
arithmetic operators
addition(+), substraction(-), multiplication(*), division(/), [salvage value(%)]
[Salvage value: if you divide two int values with eachother, just a full figure will be displayed the salvage value is for getting non divided value example:
int restvalue;
restvalue = 17 % 5;
it would display 2.]
compare operators
compare operators are used to compare most likely numeric elements. the result is this is always a boolean value, which can be saved in a boolean variable.
compare operators are:
less <
less-equal <=
greater >
grater-equal >=
equal ==(two because one = sign is used to allocate values to variables, so the "equal" operator is a ==)
disparate != or <>
logic operators
with those operators you are able to connect boolean values with eachother, these operators operate on bool variables there are 4 logic operators.
Negationoperator: it negates the containment of a boolean value. is the value false the negationoperator turns it into true is it true it turns it into false. The Negationoperator is displayed by a !
exampls.:
bool trueorfalse1;
trueorfalse1 = false;
bool trueorfalse2;
trueorfalse2 = !trueorfalse1
trueorfalse2 has the value true now.
and-operator
an and-operator is used to connect 2 boolean values if both values are true. In every other cause it would display false. its realized through a double &
example.
bool trueorfalse1, trueorfalse2, trueorfalse3;
trueorfalse1 = true;
trueorfalse2 = false;
trueorfalse3 = true;
bool result1, result2;
result1 = trueorfalse1 && trueorfalse2;
result2 = trueorfalse1 && trueorfalse3;
result1 will be false and result2 will be true.
Or-operator
it connects 2 variables witheachother and displays true, if. at least one of the values are true. The command is a | |.
example.:
bool trueorfalse1, trueorfalse2;
trueorfalse1 = false;
trueorfalse2 = true;
bool result1, result2, result3;
result1 = trueorfalse1 | | trueorfalse2;
result2 = trueorfalse1 | | false
result3 = 3 = 3(true) | | false
result1 has the value true, result2 the value false, result3 has the value true.
either-or-operator
connects 2 bools with eachother and displays true if at exact 1 value is true, in all over causes its false, its realized through a circumflex ^.
example:
bool eitheror1, eitheror2;
eitheror1 = true ^ true;
eitheror2 = true ^ false;
eitheror1 is false and eitheror2 is true.
Then you can combine operators.
int result1, result2;
result1 = 2 + 3 + 4 - 5
result2 = 4 + 20 / 3 - 8 * 2;
-Seb
Enjoy