Advertisement
avr39ripe

cppFunctionBasics

Apr 7th, 2021
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void sayHello()
  4. {
  5.     std::cout << "Hello, programm user!\n";
  6.     //std::cout << "Nice to see you!\n";
  7. }
  8.  
  9. void cycleGreeting(int greetTimes)
  10. {
  11.     //int greetTimes{ 3 };
  12.  
  13.     for (int i{ 0 }; i < greetTimes; ++i)
  14.     {
  15.         sayHello();
  16.     }
  17. }
  18.  
  19. int max(int a, int b)
  20. {
  21.     return (a > b ? a : b);
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27.  
  28.     int x{ 1 };
  29.     int y{ 20 };
  30.  
  31.     int arr[6]{ 1,5,2,3,7,0 };
  32.  
  33.     std::cout << "MAX = " << max(x, arr[3]) << '\n';
  34.  
  35.  
  36.  
  37.     std::cout << "Program starts!\n";
  38.    
  39.     int times{ 4 };
  40.  
  41.    cycleGreeting((times - 2));
  42.  
  43.     std::cout << "Program works hard!\n";
  44.  
  45.    cycleGreeting(0);
  46.  
  47.     std::cout << "Program works even more harder!\n";
  48.  
  49.    cycleGreeting(3);
  50.  
  51.     std::cout << "Program ends!\n";
  52.     return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement