Petro_zzz

lesson11_321

Aug 23rd, 2023
1,208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.64 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #define _USE_MATH_DEFINES
  4. #include <math.h>
  5.  
  6. using namespace std;
  7.  
  8. void calc_averege() {
  9.     cout << "Введите все оценки студента" << endl;
  10.     cout << "для прекращения ввода наберите 0." << endl;
  11.     int check, summ = 0, iter = 0;
  12.     cin >> check;
  13.     while (check > 0 && check <= 5) {
  14.         iter++;
  15.         summ += check;
  16.         cin >> check;
  17.     }
  18.     if (iter > 0)
  19.         cout << "Средний балл: " << (double)summ / iter << endl;
  20. }
  21.  
  22. double power(double x, int n) {
  23.     //double y = pow(x, n);
  24.     if (n == 0)
  25.         return 1;
  26.    
  27.     if (n < 0) {
  28.         n = -n;
  29.         x = 1.0 / x;
  30.     }
  31.  
  32.     double y = 1;
  33.     while (n > 0) {
  34.         n--;
  35.         y *= x;
  36.     }  
  37.     return y;
  38. }
  39.  
  40. void test_pow() {
  41.     double x;
  42.     int n;
  43.     cin >> x >> n;
  44.     cout << power(2, -4) << endl;
  45.     cout << power(2, 4) << endl;
  46.     cout << power(x, n) << endl;
  47.     cout << power(M_PI, 2) << endl;
  48. }
  49.  
  50. void multy_table() {
  51.     // x\y | 2 3 4 ....
  52.     // --------------------------
  53.     //  2  | 4  6  8
  54.     //  3  | 6  9 12
  55.     //  4  | 8 12 16
  56.     //    ...
  57.     int x = 1, y = 1;
  58.  
  59.     while (x < 10){
  60.         y = 1;
  61.         while (y < 10) {
  62.             if(y * x == 1)
  63.                 cout << "x\\y" << "\t";
  64.             else
  65.                 cout << y * x << "\t"; 
  66.             ++y;
  67.         }
  68.         x++;
  69.         cout << endl;
  70.     }
  71. }
  72.  
  73. int get_rand(int a, int b) {
  74.     return rand() % (b - a + 1) + a;
  75. }
  76.  
  77. int get_onestep(int n) {
  78.     switch (n)
  79.     {
  80.     case 1: cout << "Первая "; break;
  81.     case 2: cout << "Вторая "; break;
  82.     case 3: cout << "Третья "; break;
  83.  
  84.     default: cout << n << "-ая "; break;
  85.     }
  86.     cout << "попытка. Введи твой ответ :";
  87.     int number;
  88.     cin >> number;
  89.     return number;
  90. }
  91.  
  92. void run_game() {
  93.     /*
  94.          УГАДАЙ ЧИСЛО
  95.  
  96.     Я загадал число от 0 до 500. Попробуй его угадать.
  97.     У тебя будет 3 попытки. Если ввведёшь 0, то ты сдался.
  98.    
  99.     Певая попытка. Введи твой ответ: 26.
  100.     Неугадал. 26 меньше загаданного числа.
  101.  
  102.     Вторая попытка. Введи твой ответ: 467.
  103.     Неугадал. 467 больше загаданного числа.
  104.  
  105.     Третья попытка. Введи твой ответ: 365.
  106.     Я загадал 365. Поздравляю ты угадал число.
  107.  
  108.     Съиграем ещё? да - 1, нет - 0.
  109.     0
  110.  
  111.     Игр - 1, побед - 1, поражений - 0.
  112.     */
  113.  
  114.     cout << "          УГАДАЙ ЧИСЛО" << endl;
  115.     cout << "Я загадал число от 0 до 500. Попробуй его угадать." << endl;
  116.     cout << "У тебя будет 3 попытки.Если ввведёшь 0, то ты сдался." << endl;
  117.  
  118.     int ai_number = 55;// get_rand(1, 500);
  119.     int step = 1;
  120.     int number;
  121.     while (step <= 3) {
  122.         number = get_onestep(step);
  123.         if (number == 0) {
  124.             break;
  125.         }
  126.         if (number == ai_number) {
  127.             break;
  128.         }
  129.         step++;
  130.     }
  131.     if (number == ai_number) {
  132.         cout << "Выйгрыш" << endl;
  133.     }
  134.     else {
  135.         cout << "Поражение" << endl;
  136.     }
  137.  
  138. }
  139.  
  140. void test_rand() {
  141.     int n = 0;
  142.     cout << "time:" << time(NULL) << endl;
  143.    
  144.     while (n < 50) {
  145.         cout << get_rand(-5, 5) << endl;
  146.         n++;
  147.     }
  148. }
  149.  
  150. void test_get_onestep() {
  151.     int k = 1;
  152.     while (k < 5) {
  153.         int n = get_onestep(k);
  154.         cout << n << endl;
  155.         k++;
  156.     }
  157. }
  158.  
  159. void test_break_in_while() {
  160.     int k = 0;
  161.     while (k < 10) {
  162.         cout << k << " ";
  163.         k++;
  164.         if (k == 5){
  165.             ;
  166.             break;
  167.         }
  168.     }
  169. }
  170.  
  171. int main() {
  172.    
  173.     setlocale(LC_ALL, "ru");
  174.     srand(time(NULL));
  175.  
  176.     //calc_averege();
  177.     //cout << M_1_PI << endl;
  178.     //multy_table();
  179.     //run_game();
  180.     //test_rand();
  181.     //test_break_in_while();
  182.     run_game();
  183.     system("pause");
  184.     return 0;
  185. }
Advertisement
Add Comment
Please, Sign In to add comment