103k views
3 votes
What is wrong with the following function body?

void calculate(int count, float price, float* cost)
{
if(count < 0)
*cost = 0.0;
else
*cost = count * price;
return;
}
A) Void function must return a value.
B) nothing
C) V 0id function may not have a return statement.
D) Cannot mix reference style and value parameters.

User Jing Li
by
7.9k points

1 Answer

4 votes

Final answer:

The function provided by the student is correct. Void functions do not return a value and can have a return statement without any value, and mixing reference-style (pointer) and value parameters is valid in C/C++.

Step-by-step explanation:

The function body provided by the student is written in C or C++ and is intended to calculate the cost based on the count and price passed to it. There is nothing inherently wrong with the function body as presented. The option A) is incorrect because void functions do not return a value. Option C) is also incorrect, as void functions can have a return statement; it just cannot return any value. Finally, option D) is incorrect because mixing reference-style parameters (pointers in C/C++) with value parameters is perfectly valid in C and C++. Therefore, the correct answer is B) nothing; there is no mistake in the provided function body.

User Gennie
by
8.3k points