float mult ( float x, float y, float z );
int main()
{
float x;
float y;
float z;
cout << "input three numbers to be multiplied: ";
cin >> x >> y >> z;
cin.ignore();
cout << product of three numbers: " << mult ( x, y, z ) << "\n";
cin.get();
}
float mult ( float x, float y, float z )
{
return x * y * z
}
You aren't returning anything. When you type in return 0; then you are returning '0' as the data type of the function. The variables used inside the function don't really matter in this context in any way I can think of. If in Dacster13's example the value of function would be an int data type if he were returning it, but again return 0;.
Also what seems strange is all that is necessary to change this code from multiplication to Sum or
Subtraction or Division or possibly other mathematical solutions is to simply change signs:
1 2 3
return ( x * y * z ) or ( x + y + z ) or ( x - y - z ) or ( x / y / z )
Dacaster13 didn't interperate the question the same way I did. I saw it as you asking why you can use a float value inside of a function that is an int data type. This is because the value of the variables don't matter until one is returned. The function then takes on the value of that function and its data type. So if main() returned anything except '0' and another process was expecting something from it, then that other process would get the data as an int.