130k views
1 vote
What is wrong with this function? float Test2(int i, float x)

{ i = i + 7; x = 4.8 + float(i); }

1 Answer

6 votes

Final answer:

The code is missing a return statement at the end.

Step-by-step explanation:

The code is missing a return statement at the end. In C++, if a function is declared to return a value, it must have a corresponding return statement. In this case, the function Test2 is declared to return a float, but there is no return statement in the code.

Here's the corrected code:

float Test2(int i, float x){ i = i + 7; x = 4.8 + float(i); return x; }

Now the function correctly returns the value of the variable x.

User Tonlika
by
7.4k points