Assuming a, b, and sum are what you want to do if test equals 2, yes. Also, you don't set test to any value. sum should also be set prior to the if test in case test != 2. You're returning sum in either case. You could put that return in the if block {}, but would still need to return something if the if block wasn't executed. Also, the syntax is: return sum; not return (sum);Originally posted by Unregistered
I know this is legal in the body of int main()
if( test == 1){
++count;
}
my question is the {,} required in a function body of the if statement, because in my book's example all I see is this:
double test(double a, double b)
{
double test, sum;
//is {,} required for this one?
if(test ==2)
a = 2.0;
b = 2.0;
sum = a + b;
return(sum);
}