123k views
3 votes
Can you find the reason that the following pseudocode does not perform as indicated in the comments?

// Find the error in the following pseudocode.
Module main()
Declare Real value, result
// Get a value from the user.
Display "Enter a value."
Input value
// Get 10 percent of the value.
Call tenPercent(value)
// Display 10 percent of the value.
Display "10 percent of ", value, " is ", result
End Module
// The tenPercent function returns 10 percent
// of the argument passed to the function.

Function Real tenPercent(Real num)

Return num * 0.1

End Function

1 Answer

4 votes

Answer:

The value of the variable "result" is never set anywhere in the code. In other words, variable "result" is declared but never given a value.

Step-by-step explanation:

The call to the function "tenPercent(value)" on line 8 of the code returns the product of "value" and 0.1 i.e value * 0.1 as stated in the function declaration on lines 14, 15 and 16.

The returned value from this call to the function "tenPercent(value)" should be stored in the variable "result". This can then be displayed as written on line 10.

User Sagar Koshti
by
5.5k points