Muhammad Magdi
Data Type | Description |
---|---|
int | Small integer number |
double | Large real number |
long long | Large integer number |
string | A sequence of characters (word) |
char | A single character |
bool | Boolean number (0 or 1) |
Sometimes we need to execute statements depending on particular conditions, so we use if conditions:
if ( CONDITION#1 ) {
TRUE-STATEMENTS#1
} else if ( CONDITION#2 ) {
TRUE-STATEMENTS#2
} else if ( CONDITION#3 ) {
TRUE-STATEMENTS#3
} ... and so on
... else {
FALSE-STATEMENTS
}
Arithmetic (in Calculations) Operators in C++ are:
Operator | Meaning |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Integer Division |
% | Remainder after Division (Mod) |
Relational (in Conditions) Operators in C++ are:
Operator | Meaning |
---|---|
== | equal to |
!= |
not equal to |
< | less than |
> | greater than |
<= | less than or equal |
>= | greater that or equal |
Logical (in Conditions) Operators in C++ are:
Operator | Meaning |
---|---|
&& | AND |
|| | OR |
! | NOT |
#include <iostream>
using namespace std;
int main(){
int a, b;
char op;
cin >> a >> op >> b;
if (op == '+') {
cout << a + b << endl;
} else if (op == '-') {
cout << a - b << endl;
} else if (op == '*') {
cout << a * b << endl;
} else if (op == '/') {
cout << a / b << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main(){
int start, end;
cin >> start >> end;
if (start < end) {
cout << "O JOGO DUROU " << end - start << " HORA(S)" << endl;
} else {
cout << "O JOGO DUROU " << 24 - start + end << " HORA(S)" << endl;
}
return 0;
}
There are two cases:
Case 1:
When the game starts and ends within the same day.
In this case start will be less than end.
So the Duration will be the difference end - start.
Case 2:
When the game starts in a day and ends in the following one.
In this case start will be greater than end, as it started late (with large value) in day1 and ended early (with small value) in day2.
So the Duration here is consisted of 2 parts:
Day1 Part = 24 - start
Day2 Part = end
Duration = 24 - start + end