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
In the above pseudocode, our main motto is to display the total mileage. In the getMileage() module the input variable 'mileage' is a local variable, which belongs only to the getMileage() module. So, In the main() module the referenced variable 'mileage' is not intialized.
In other words when the getMileage() module is called in the main() module, it asks for a input value for mileage variable. When the value is given it is stored in the variable mileage which is local to getMileage() module. So, the value or the variable is not associated with the Main() module.
The error is that the mileage variable is local to only getMileage() module but not main() module. To get the desired output i.e. to display the mileage, the statement "You've driven a total of ", mileage, " miles." in the main() module has to be placed in the getMileage() module after the 'input mileage' statement.
Get Answers For Free
Most questions answered within 1 hours.