Advertisement
Petro_zzz

311_1202

Feb 12th, 2024
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void task0() {
  6.     const int x1 = 1;
  7.     const int x2 = 2;
  8.     const int x3 = 3;
  9.     int x;
  10.  
  11.     cout << "Enter x: "; cin >> x;
  12.  
  13.     switch (x) {
  14.     case x1: cout << "Moning\n"; break;
  15.     case x2: cout << "Afternoon\n"; break;
  16.     case x3: cout << "Night\n"; break;
  17.     default: cout << "Good\n";
  18.     }
  19. }
  20.  
  21. void task1() {
  22.     // Поименованные целочисленные константы
  23.     enum Buttons {
  24.         STOP = 1,
  25.         PLAY = 2,
  26.         NEXT = 3,
  27.     };
  28.     Buttons button1 = Buttons::STOP;
  29.  
  30.     switch (button1)    {
  31.         case STOP: cout << "Stop\n"; break;
  32.         case PLAY: cout << "Play\n"; break;
  33.         case NEXT: cout << "Next\n"; break;
  34.         default: break;
  35.     }
  36. }
  37.  
  38. void bad_practic() {
  39.    
  40. marker1:
  41.     task0();
  42.    
  43.     char answer;
  44.     cout << "Do you want repeat? 'y/n' ";
  45.     cin >> answer;
  46.     if (answer == 'y') {
  47.         goto marker1;
  48.     }
  49.     //cout << "Hello\n";
  50. }
  51.  
  52. void test_while() {
  53.     // Сумма алгебр. последовательности
  54.     // 1 + 2 + 3 + 4 + 5
  55.  
  56.     int sum = 1 + 2 + 3 + 4 + 5;
  57.     cout << sum << endl;
  58.  
  59.     int sum1 = 0;
  60.     sum1 = sum1 + 1;
  61.     sum1 = sum1 + 2;
  62.     sum1 = sum1 + 3;
  63.     sum1 = sum1 + 4;
  64.     sum1 = sum1 + 5;
  65.     cout << sum1 << endl;
  66.  
  67.     int n = 1;
  68.     int sum2 = 0;
  69.     while (n <= 5) {
  70.         //cout << n << " ";
  71.         sum2 = sum2 + n;
  72.         n += 1;
  73.     }
  74.     cout << sum2 << endl;
  75. }
  76.  
  77. void horizontal() {
  78.     int max_num;   
  79.  
  80.     cout << "Enter max_num: ";
  81.     cin >> max_num;
  82.  
  83.     while (max_num > 0) {
  84.         cout << max_num << " ";
  85.         max_num -= 1;
  86.     }
  87. }
  88.  
  89. void show_sqrtab() {
  90.     int x = 0;
  91.     cout << "\tx\t|\tx^2\n";
  92.     cout << "------------------------------\n";
  93.     while (x <= 20) {
  94.         cout << "\t" << x
  95.              << "\t|\t"
  96.              << x * x << endl;
  97.         x += 1;
  98.     }
  99. }
  100.  
  101. int main() {
  102.     //bad_practic();
  103.     //test_while();
  104.     //horizontal();
  105.     //show_sqrtab();
  106.  
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement