You made a very common beginners mistake. You forgot to prototype your functions outside the main function. Then, call them within your main. Also, I would move your tourType destination within your main, otherwise you create a global variable (not good practice to have global variables).
Could someone explain to me the idea of parameters of a function. I'm very confused when you include parameters and when you don't. I'm just completely lost on when I need them. I know when I want to print something out I don't need to pass anything in to the function. However, i don't understand what "passing" means. I've flipped back to the functions chapter in my c++ programming book but still cannot get that light bulb to come on in my head.
It would be nice if someone could explain what goes in these ( ).
Also I've been told that when I'm creating a function that prints something I don't need it to pass anything or return anything. I just don't understand when I need to return or use the void. it seems to me that if i'm going to assign something in a function i should return that to the program so the program knows what I just assigned.
1. Function Prototypes
These are not strictly necessary. They are only needed if you define a function below where it is used in your code. So if you use a function in main, it better either be defined before main or else have a prototype before main. A function prototype consists of the return type of the function, the name of the function, and the data types of the parameters, with the parameter names as optional. Example of a function prototype:
int sum(int, int);
2. Function Definition
This is what you call the code that makes up your function. It starts out like a function prototype, but you must have names for the parameters. You can also give default values for the parameters if you want. Example of a function definition:
1 2 3 4 5
int sum(int a = 0, int b = 0)
//so if the function is called without passing any arguments, a and b are both 0
return a + b;
3. Function Calls
This is the piece of code that actually tells the program to use your function. Example of a function call passing x and y as arguments: SumOfXAndY = sum(x, y);
The stuff in the parentheses are called arguments when it's a function call, and parameters when it's a function definition or function prototype.
Topic archived. No new replies allowed.
You are using a version without Ads of this website. Please, consider donating: