I'm trying to pass by reference. I know you have to add an ampersand to the function prototype, but im not quite sure what i am supposed to put in the function description.
Umm..Firstly you need amperstand in your prototype secondly that's not how you use references you would return void and set a new value for celsius and it will directly modify the varaible being passed as a param.
The function definition has to match the declaration. You can leave out the variable name(s) in the definition but they are usually included for clarity.
So double celsius_to_fahrenheit(double &); will compile
but double celsius_to_fahrenheit(double &celsius); is preferred.
Passing by reference is best used in two situations (of which neither apply here):
1) The object passed is a complex class which will be expensive to copy
2) You want to modify the original object in your function
Also, when I declare references i like to do this double& celsius instead of double &celsius. This is a personal preference but I like it because in this case, & is not getting the address, but is part of the type. You are saying "I want a reference to a double". Similarly, for pointers I like: double* celsius over double *celsius. I only attach the * to the object when I am dereferencing.
So to answer your question directly, you would do this:
1 2 3 4 5 6 7 8 9 10 11 12
void setToZero(double& value);
int main()
{
double something;
setToZero(something); // something gets set to 0.0;
}
void setToZero(double& value)
{
value = 0.0;
}