Advertisement
bhok

3.2 Functions 2

Jul 12th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. // More tutorials at BrandonHok.com
  2. #include <iostream>
  3.  
  4. // Functions 3.2 - More Bites
  5.  
  6. // If I could make a metaphor on how to relate functions and food
  7. // The class would be the Oreo cookie and the functions would be the cream inside.
  8.  
  9. // How To Make A Function Part 2
  10. // Also known as methods or procedures in other languages.
  11.  
  12. // Starting With A Prototype Function
  13.  
  14. // A prototype (or function declaration) tells
  15. // the compiler the name, return type, number and type of parameters to expect.
  16.  
  17. // In thus, what is the return type? How would you define it in your terms?
  18. // Where can we find the parameters in our code? After what? Enclosed by?
  19.  
  20. // Section 1
  21. // Type the code below until the next section and answer the comments on a separate paper or within your compiler.
  22.  
  23. void hotdog(int buns, int dogs);
  24. void corndogs(int corn, int sticks);
  25.  
  26. int main()
  27. {
  28.     hotdog(2, 5); // This is our function call and the numbers we are putting in.
  29.     system("pause");
  30. }
  31.  
  32.  
  33. // This will be our actual function that will have a return type of void
  34. void hotdog(int buns, int dogs)
  35. {
  36.     std::cout << "You have this many buns: " << buns << std::endl;
  37.     std::cout << "You have this many dogs: " << dogs << std::endl;
  38.  
  39. }
  40.  
  41. // What is the difference between the last function example found in section 3.1 and this function?
  42. // Try making two functions one with a prototype and the other without.
  43. // Understanding the differences between the two is very important!
  44. // Prototypes are very important for large scale programs!!!
  45.  
  46. // Code Review
  47. // What if we made a function with a prototype that uses char instead of int? Can you make that work?
  48. // You may need to do some side research and figure out what char does.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement