Initial commit
This commit is contained in:
55
cpp/Структуры/if.cpp
Normal file
55
cpp/Структуры/if.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
|
||||
/*
|
||||
if (condition) {
|
||||
statement1;
|
||||
statement2;
|
||||
...
|
||||
} else if (condition2) {
|
||||
statement3;
|
||||
statement4;
|
||||
...
|
||||
} else {
|
||||
statement 5;
|
||||
statement 6;
|
||||
...
|
||||
}
|
||||
Работает только потому, что единственное выражение не требует {}
|
||||
Иначе это записывалось бы как:
|
||||
if (condition) {
|
||||
statement1;
|
||||
statement2;
|
||||
...
|
||||
} else {
|
||||
if (condition2) {
|
||||
statement3;
|
||||
statement4;
|
||||
...
|
||||
} else {
|
||||
statement5;
|
||||
statement6;
|
||||
...
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
int inp;
|
||||
|
||||
cout << "Введите число: ";
|
||||
cin >> inp;
|
||||
cout << endl;
|
||||
|
||||
if (inp > 5) {
|
||||
cout << "Ваше число больше 5" << endl;
|
||||
} else if (inp == 5) {
|
||||
cout << "Ваше число равно 5" << endl;
|
||||
} else {
|
||||
cout << "Ваше число меньше 5" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
41
cpp/Структуры/switch.cpp
Normal file
41
cpp/Структуры/switch.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
int main() {
|
||||
/*
|
||||
Синтаксис:
|
||||
switch(var:int) {
|
||||
case n:int: (возможно накопление)
|
||||
statement;
|
||||
break;
|
||||
default:
|
||||
statement;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
int inp;
|
||||
|
||||
cout << "Введите оценку: ";
|
||||
cin >> inp;
|
||||
cout << endl;
|
||||
|
||||
switch (inp) {
|
||||
case 10:
|
||||
case 9:
|
||||
cout << "The grade is A" << endl;
|
||||
break;
|
||||
case 8:
|
||||
cout << "The grade is B" << endl;
|
||||
break;
|
||||
case 7:
|
||||
cout << "The grade is C" << endl;
|
||||
break;
|
||||
case 6:
|
||||
cout << "The grade is D" << endl;
|
||||
break;
|
||||
default:
|
||||
cout << "The grade is F" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user