196k views
3 votes
Find the error in the following pseudocode.

Module main()
Declare Real mileage
Call getMileage()
Display "You've driven a total of ", mileage, " miles."
End Module
Module getMileage()
Display "Enter your vehicle’s mileage."
Input mileage
End Module

User Jared Beck
by
3.6k points

2 Answers

3 votes

Final answer:

The error in the pseudocode is the lack of variable passing between the main and getMileage modules, which prevents the main module from displaying the correct mileage. The mileage variable must be passed by reference to the getMileage module to be properly modified.

Step-by-step explanation:

The error in the pseudocode provided is that the variable mileage is declared in the main module but is not passed as an argument to the getMileage module. This means that the getMileage module does not have access to the mileage variable declared in the main module and cannot modify it. To fix this error, the mileage variable should be passed by reference to the getMileage module, allowing it to modify the original variable. Here's how the corrected pseudocode should look:

Corrected Pseudocode:

Module main()
Declare Real mileage
Call getMileage(mileage)
Display "You've driven a total of ", mileage, " miles."
End Module

Module getMileage(Ref Real mileage)
Display "Enter your vehicle’s mileage."
Input mileage
End Module

Additionally, the getMileage function should have a way to return the entered value to the calling function or directly modify the reference to the variable provided.

User Myrl
by
4.9k points
1 vote

Answer:

Following are the error in the given program are explain in the explanation part .

Step-by-step explanation:

The main() function call the function getMileage() function after that the control moves to the getMileage() definition of function. In this firstly declared the "mileage" variable after that it taking the input and module is finished we see that the "mileage" variable is local variable i,e it is declared inside the " Module getMileage() " and we prints in the main module that are not possible to correct these we used two technique.

Technique 1: Declared the mileage variable as the global variable that is accessible anywhere in the program.

Technique 2: We print the value of "mileage" inside the Module getMileage() in the program .

User Momen Zalabany
by
4.6k points