Hey there fellow coders, I'm having a little bit of a hard time understanding functions. What is a function prototype? What is an example? Hell I just need some guidance to some information that makes is easy to understand.
I need to make a program that uses a few functions and I'm not sure if I get the whole concept. An example would be
Define a make_sterling function that takes thee integers representing pounds,
shillings, and pence (in that order) and returns a sterling structure.
would this be done in my header file or just the .cpp file? help? thanks
Let's say you want to go and buy some bread. You go into the bread store and ask for some bread at a price. You give the cashier some money and the cashier in turn gives you bread. Functions are kinda the same idea:
1 2 3 4 5 6 7 8 9 10 11
Bread BuyBread(float Price)
if(BreadPrice == Price)
cout<<"Here is some Bread"<<endl;
The above function called BuyBread returns a bread when you send it a price.
So now anytime any part of your program wants to buy bread, you just call buy bread.
A function is basically like a program inside of a program.. you take a block of code and name it whatever you want your function name to be. If you need it in the future you would call on it from wherever you want it to work from.. lol sorry i dont think I explained it very well but hopfully you get it :). Happy coding!!