[Solved] How do I return a double? [closed]


Ok, you basically have it right, but you are not yet multiplying the argument value. So your function should be

double functionXYZ (double data)
{
    return data * 10;
}

The type before the function name determines its ‘return type’ (what type of variables can be expected to be returned by this function). In this case, it is double, so as long as you use the return keyword with a double value, you are correctly returning a double.

Edit

There are also a number of bugs in your main() function. To get this to compile correctly, you must do the following:

Make sure variables have unique names; You have double val several times. That means you are trying to declare to the compiler that there is a double variable called val more than once, which is an error.

Change the line(s) that look like this

printf(" Your total is: %if \ n " result1);

to

printf(" Your total is: %if \n ", result1);

Note adding the missing comma. Also removing the space between the \ and the n is not a compile bug but it is an obvious typo.

Make sure that every time you refer to a variable, it is one you have actually defined. So for example

double result2 = functionXYZ (val2);

calls your function with a variable called val2, except at no point in your code to you actually define val2.

10

solved How do I return a double? [closed]