Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // More tutorials at BrandonHok.com
- #include <iostream>
- // Functions 3.2 - More Bites
- // If I could make a metaphor on how to relate functions and food
- // The class would be the Oreo cookie and the functions would be the cream inside.
- // How To Make A Function Part 2
- // Also known as methods or procedures in other languages.
- // Starting With A Prototype Function
- // A prototype (or function declaration) tells
- // the compiler the name, return type, number and type of parameters to expect.
- // In thus, what is the return type? How would you define it in your terms?
- // Where can we find the parameters in our code? After what? Enclosed by?
- // Section 1
- // Type the code below until the next section and answer the comments on a separate paper or within your compiler.
- void hotdog(int buns, int dogs);
- void corndogs(int corn, int sticks);
- int main()
- {
- hotdog(2, 5); // This is our function call and the numbers we are putting in.
- system("pause");
- }
- // This will be our actual function that will have a return type of void
- void hotdog(int buns, int dogs)
- {
- std::cout << "You have this many buns: " << buns << std::endl;
- std::cout << "You have this many dogs: " << dogs << std::endl;
- }
- // What is the difference between the last function example found in section 3.1 and this function?
- // Try making two functions one with a prototype and the other without.
- // Understanding the differences between the two is very important!
- // Prototypes are very important for large scale programs!!!
- // Code Review
- // What if we made a function with a prototype that uses char instead of int? Can you make that work?
- // You may need to do some side research and figure out what char does.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement