This is part 1 of C++ basics and a part 2 to my Blog post about C basics.
c++
#include <iostream> = Basic input/output library
#include <iostream> = Basic input/output library
std::cout<<“blabla” ;
std::cout<<Variable<<std::endl;
std::cout<<Variable<<std::endl;
Print something
endl = end line = new line
std::cin>>Variable;
Scan something in
every command ends with ;
Declare a variable
Variable needs to be declared by data type, before we can use it
std::cin>>Variable;
Scan something in
every command ends with ;
Declare a variable
Variable needs to be declared by data type, before we can use it
int main() {
int StudentId;
char Class;
int age = 10;
std::string = “Gerard Way”;
char Class;
int age = 10;
std::string = “Gerard Way”;
}
Data types
int = integer numbers = 0, 4, 234
double = floating-point numbers = 3.14, 8.33, 345.90
char = characters = ‘a’, ‘lol’, ‘moist’
string = sequence of characters = “Hello world!”, “my name is”
bool = truth values = true / false
Arithmetic operators
int addition = 10+2;
int subtraction = 10 -2;
int multiplication = 10*2;
int division = 10/2;
int squareRoot = sprt(10);
modulo = 10%2; (divides and gives the remainder)
Chaining
std::cout << “Hello, my name is “<< name << “and I am” << age
<<“years old.”<< std::endl;
Example :
#include <iostream>
int main() {
int tip = 0;
std::cout << "Enter tip amount: ";
std::cin >> tip;
std::cout << "you paid " << tip << " dollars"<<std::endl;
}
int main() {
int tip = 0;
std::cout << "Enter tip amount: ";
std::cin >> tip;
std::cout << "you paid " << tip << " dollars"<<std::endl;
}
Loops, if, else if, and else
I already covered this in my c post: C Basics
they are the same as in C
Operators
== equal to
!= not equal to
> greater than
>= greater or equal to
< less than
<= less or equal to
Logical Operators
&& = and
|| = or
! = not
easy example
I already covered this in my c post: C Basics
they are the same as in C
Operators
== equal to
!= not equal to
> greater than
>= greater or equal to
< less than
<= less or equal to
Logical Operators
&& = and
|| = or
! = not
easy example
include <iostream>
int main() {
int day = 6;
if(day == 6 || day == 7){
std::cout<<"Weekend"
}
}
Comments
Displaying 1 of 1 comments ( View all | Add Comment )
Timo
I love you
Report Comment
leave me alone
by テ オ; ; Report