Question

Find the error in the following pseudocode. Module main()     Declare Real mileage     Call getMileage()...

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

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Find the error in the following psuedocode // This program asks the user to enter a...
Find the error in the following psuedocode // This program asks the user to enter a number between 1 and 5 and validates the input. Declare Integer number // Get a number from the user. Display "Enter a number between 1 and 5." Input number // Make sure the number is between 1 and 5. While number < 1 AND number > 5 Display "ERROR: The number must be between 1 and 5. " Display "Enter a number between 1...
Can you find the reason that the following pseudocode function does not return the value indicated...
Can you find the reason that the following pseudocode function does not return the value indicated in the comments? // The setDiscountPrice function accepts an item's price and the discount percentage // as arguments. It uses those values to calculate and return the discounted price. Function Real setDiscountPrice(Real price, Real percentage)      // Set the discount.      Declare Real discount = price * percentage      // Subtract the discount from the price.      Declare Real discountPrice = price - discount      // Return the discount...
using System; public static class Lab5 { public static void Main() { // declare variables int...
using System; public static class Lab5 { public static void Main() { // declare variables int inpMark; string lastName; char grade = ' '; // enter the student's last name Console.Write("Enter the last name of the student => "); lastName = Console.ReadLine(); // enter (and validate) the mark do { Console.Write("Enter a mark between 0 and 100 => "); inpMark = Convert.ToInt32(Console.ReadLine()); } while (inpMark < 0 || inpMark > 100); // Use the method to convert the mark into...
IN JAVA Complete the following program. Add codes in the main method to:1) call method average(double[]...
IN JAVA Complete the following program. Add codes in the main method to:1) call method average(double[] gpaarr ) to calculate the average of gpaArray; 2) add codes in the for loop to calculate sum 3) print the average . public class Test { public static void main (String args[]) { double[ ] gpaArray = { 2.5, 4.0, 3.8, 3.2, 2.9, 4.0 } ;   //add your codes here (you can put your codes in the Answer area with/without copying the original...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation....
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation. case:    W17400 APIGEE: PEOPLE MANAGEMENT PRACTICES AND THE CHALLENGE OF GROWTH Ranjeet Nambudiri, S. Ramnarayan, and Catherine Xavier wrote this case solely to provide material for class discussion. The authors do not intend to illustrate either effective or ineffective handling of a managerial situation. The authors may have disguised certain names and other identifying information to protect confidentiality. This publication may not be...