Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. // PREDEFINED FUNCTIONS
  2. //______________________________________________________________
  3.  
  4. // a predefined function is something already created by somebody else for you to use
  5.  
  6.  
  7.  
  8.  
  9. //function prototype  (declaring its there but nothing within it)
  10. //int numbers(int num1, int num2);// 1st int - return type, function name - add, parameters - (int num1, int num2)
  11.  
  12. /*int main()
  13. {
  14.    
  15.     cout << "8 + 1 + 1" << endl;
  16.     // funciton call
  17.     cout << numbers(8, 1) << endl;
  18.  
  19.     system("pause");
  20.     return 0;
  21. }
  22.  
  23.  
  24.  
  25.  
  26. // function body
  27. int numbers(int num1, int num2)
  28. {
  29.     return num1 + 1 + num2;
  30. }
  31.  
  32.  
  33.  
  34. int main()
  35. {
  36.     // cos is a pre-defined dunction that calculates the cosone of the target (number)
  37.     cout << cos(5.5) << endl;
  38.    
  39.     system("pause");
  40.     return 0;
  41. }
  42. _________________________________________________________________________________________
  43.  
  44. //GLOBAL and LOCAL  Variables
  45. int num = 10;//  - declares it and affects the whole file instead of it being in int main (can access iy anywhere)
  46. void printName();
  47.  
  48. int main()
  49. {
  50.     // local variables - delcared but can only be used inside the function so in this case it can only be used inside main
  51.  
  52.     // global
  53.     printName();
  54.     system("pause");
  55. }
  56.  
  57. void printName()
  58. {
  59. for (int i = 0; i < num; i++)
  60.     {
  61.     cout << "Joshua" << endl;
  62.     }
  63. }
  64.  
  65. ___________________________________________________________________________________________
  66.  
  67.  
  68. // fixed loop
  69. for (int = 0;i < 11; i++)
  70. {
  71. cout << i << endl;
  72.  
  73. }
  74.   // post checked loop
  75. int a = 20;
  76. do
  77. {
  78. cout << "hello"
  79.  
  80. } while (a != 20);
  81.   // pre checked loop
  82. int a = 5;
  83. while (a != 5)
  84. {
  85.     cout << "hello" << endl;
  86.    
  87. }
  88.  
  89.  
  90.  
  91. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement