I have a double function and I'm wondering if it can return two values. if not how do i make a function that can. Here is the function:
1 2 3 4 5 6 7 8 9 10 11 12 13
double requestRadius(double radmin, double radmax)
{
printf("\nEnter the minimum and maximum values for radius:");
scanf("%lf %lf", &radmin, &radmax);
while (radmin<=0 || radmax<radmin || radmin==radmax)
{
printf("%lf and %lf are invalid selections. \n\nThe minimum radius must be greater than 0. \nand the maximum must be greater than the minimum. \nThe min and max values cannot be the same\n",radmin,radmax);
printf("\n\nEnter the minimum and maximum values for radius:");
scanf("%lf %lf", &radmin, &radmax);
};
printf("\n\tRadius range: %lf - %lf",radmin,radmax);
return radmin,radmax;
}
// note: returns void, but takes 'double&' (with a '&')
void requestRadius(double& radmin, double& radmax)
{
printf("\nEnter the minimum and maximum values for radius:");
scanf("%lf %lf", &radmin, &radmax);
while (radmin<=0 || radmax<radmin || radmin==radmax)
{
printf("%lf and %lf are invalid selections. \n\nThe minimum radius must be greater than 0. \nand the maximum must be greater than the minimum. \nThe min and max values cannot be the same\n",radmin,radmax);
printf("\n\nEnter the minimum and maximum values for radius:");
scanf("%lf %lf", &radmin, &radmax);
};
printf("\n\tRadius range: %lf - %lf",radmin,radmax);
// return radmin,radmax; <- no need to return anything
}
it's just the same, it's returned values "implicitly" :D else, you can make two separate functions (in case you want to returned the values in different variables)...
Yeah, when functions are passed variables by reference the variable data itself is changed rather than a copy of the data. The variables don't have function scope when passed by reference so it gets changed and is saved outside the function rather than being erased after leaving the function.
is saved outside the function rather than being erased after leaving the function
i prefer, it's saved within the function. in fact, the value is changed within the function, which means, the original value of the variable is been changed and thus, it won't be necessary saved.