avr39ripe

PV024functionAdv

Nov 5th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. bool startNuclearWar{ false };
  5.  
  6.  
  7.  
  8. // 10 20
  9. int genRand(int minVal, int maxVal)
  10. {
  11.     return (rand() % (maxVal - minVal) + minVal);
  12. }
  13.  
  14. int max(int a, int b)
  15. {
  16.     return (a > b ? a : b);
  17. }
  18.  
  19. //maxPrint(x, y, true);
  20. // maxPrint(answer, (maxPrint(x, y, false) + genRand(10,20))+2, true);
  21. int maxPrint(int a, int b, bool print)
  22. {
  23.     //int a{x};
  24.     //int b{};
  25.     //bool print{true};
  26.  
  27.     int maxVal{ a > b ? a : b };
  28.  
  29.     if (print)
  30.     {
  31.         std::cout << "maxPrint -> max = " << maxVal << '\n';
  32.     }
  33.  
  34.     return maxVal;
  35. }
  36.  
  37. int count()
  38. {
  39.     const int maxVal{ (rand() % 11) + 1 };
  40.  
  41.     //std::cout << "count() -> maxVal = " << maxVal << '\n';
  42.  
  43.     int sum{ 0 };
  44.  
  45.     for (int i{ 0 }; i < maxVal; ++i)
  46.     {
  47.         sum += i;
  48.         //std::cout << "Sum = " << sum << ' ';
  49.     }
  50.     //std::cout << '\n';
  51.     //std::cout << "Sum of numbers from 0 to some random [0..10] is " << sum << '\n';
  52.     return sum;
  53. }
  54.  
  55. void sayHello()
  56. {
  57.     startNuclearWar = true;
  58.     std::cout << "\n#####\n";
  59.     std::cout << "Hello, I'm sayHello function!\n";
  60.     if (rand() % 2)
  61.     {
  62.         return;
  63.     }
  64.     std::cout << "I'm useless, but nice function! :()\n";
  65.     std::cout << "\n#####\n";
  66.     return;
  67. }
  68.  
  69. void testFun()
  70. {
  71.     std::cout << "i'm testFun\n";
  72. };
  73.  
  74. void sayGoodbye()
  75. {
  76.     testFun();
  77.     std::cout << "Simply bye!\n";
  78. }
  79.  
  80.  
  81. void swapVal(int num1, int num2);
  82.  
  83. const int correctAnswer{ 42 };
  84.  
  85.  
  86.  
  87. int arrG[10]{ 23,56,788,3 };
  88.  
  89. void checkState()
  90. {
  91.     /// ????
  92.     ///
  93.     ///
  94.     startNuclearWar = false;
  95. }
  96.  
  97. int counter()
  98. {
  99.     static int cnt{ 0 };
  100.     return ++cnt;
  101. }
  102.  
  103. void printArr(int arrPrn[], int arrSize)
  104. {
  105.     for (int i{ 0 }; i < arrSize; ++i)
  106.     {
  107.         arrPrn[i] = genRand(10, 30);
  108.  
  109.         std::cout << arrPrn[i] << ' ';
  110.     }
  111.     std::cout << '\n';
  112. }
  113.  
  114. int main()
  115. {
  116.     const int arrSize{ 10 };
  117.     const int arrSize1{ 5 };
  118.     int arr[arrSize]{};
  119.     int arr1[arrSize1]{};
  120.  
  121.     int x{};
  122.     int y{};
  123.  
  124.     //for (int i{ 0 }; i < 5; ++i)
  125.     //{
  126.     //  std::cout << counter() << ' ';
  127.     //}
  128.     //std::cout << '\n';
  129.  
  130.     /*int k{ 10 };
  131.     int j{ 20 };
  132.  
  133.  
  134.     std::cout << "k = " << k << " j = " << j << '\n';
  135.     swapVal(k, j);
  136.     std::cout << "k = " << k << " j = " << j << '\n';
  137.  
  138.     return 0;*/
  139.     const int answer{ 42 };
  140.  
  141.     int val{};
  142.  
  143.     std::cout << "Start of the programm\n";
  144.     srand(time(0));
  145.  
  146.     //std::cout << "Enter A value\n";
  147.     //std::cin >> x;
  148.  
  149.     //std::cout << "Enter B value\n";
  150.     //std::cin >> y;
  151.  
  152.     ////std::cout << "Max = " << max(a,b) << '\n';
  153.     //std::cout << "Max from X and Y is: " << maxPrint(x, y, false) << '\n';
  154.  
  155.     ////std::cout << "Complete answer is: " << max(answer, max(x, y)) << '\n';
  156.     //maxPrint(answer, (maxPrint(x, y, false) + genRand(10,20))+2, true);
  157.  
  158.     printArr(arr, arrSize);
  159.     printArr(arr1, arrSize1);
  160.  
  161.     //for (int i{ 0 }; i < arrSize; ++i)
  162.     //{
  163.     //  arr[i] = genRand(10,30);
  164.     //  if (i < arrSize1)
  165.     //  {
  166.     //      arr1[i] = genRand(40, 50);
  167.     //  }
  168.  
  169.     //}
  170.  
  171.     //printArr(arr, arrSize);
  172.     //printArr(arr1, arrSize1);
  173.     for (int i{ 0 }; i < arrSize; ++i) { std::cout << arr[i] << ' '; } std::cout << '\n';
  174.     for (int i{ 0 }; i < arrSize1; ++i) { std::cout << arr1[i] << ' '; } std::cout << '\n';
  175.  
  176.     //for (int i{ 0 }; i < arrSize; ++i) { std::cout << arr[i] << ' '; } std::cout << '\n';
  177.     //for (int i{ 0 }; i < arrSize; ++i) { std::cout << arr1[i] << ' '; } std::cout << '\n';
  178.  
  179.     return 0;
  180.  
  181.     std::cout << "Sum of numbers from 0 to some random [0..10] is " << count() << '\n';
  182.     //count();
  183.  
  184.     //std::cout << "Val = " << (val = rand() % count()) << '\n';
  185.  
  186.  
  187.     ////sayHello();
  188.     //std::cout << "some actions in programm...\n";
  189.  
  190.     //sayHello();
  191.  
  192.     //std::cout << "Another actions some actions in programm...\n";
  193.  
  194.     //sayHello();
  195.  
  196.     //std::cout << "Some MORE actions in programm...\n";
  197.  
  198.     //sayGoodbye();
  199.  
  200.     return 0;
  201. }
  202.  
  203. void swapVal(int num1, int num2)
  204. {
  205.     std::cout << "num1 = " << num1 << " num2 = " << num2 << '\n';
  206.     int tmp{ num1 };
  207.     num1 = num2;
  208.     num2 = tmp;
  209.     std::cout << "num1 = " << num1 << " num2 = " << num2 << '\n';
  210. }
Advertisement
Add Comment
Please, Sign In to add comment