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/errors in the following pseudo code. Describe the place or line in the code...
Find the error/errors in the following pseudo code. Describe the place or line in the code where the error will occur and give a clear explanation Module main() Declare Integer value1, value2, value3 Display "Enter the first value." Input value1 Display "Enter the second value." Input value2 Display "Enter the third value." Input value3 Set sum = value1 + value2 + value3 Display The sum of numbers is , sum End Module
What will be the expected output of the following pseudo code? Write exactly what would display...
What will be the expected output of the following pseudo code? Write exactly what would display when you execute the statements. Module main() Declare Integer number Display "Enter a number and I will display" Input number Call doubleNumber(number) Display number End Module Module doubleNumber(Integer value) Declare Integer result Set result = value * 2 Display result End Module
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...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features the design of a calculator program using pseudocode and a Python program that uses a list and functions with variable scope to add, subtract, multiply, and divide. Open the M4Lab1ii.py program in IDLE and save it as M4Lab1ii.py with your initials instead of ii. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and...
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...
Design a pseudocode program that loads an array with the following 7 values. Add one more...
Design a pseudocode program that loads an array with the following 7 values. Add one more word (of your own choosing) for a total of 8 words. biffcomelyfezmottleperukebedraggledquisling Be sure to use lowercase, as shown above. This will make the processing easier. • Ask the user to enter a word • Search through this array until you find a match with the word the user entered. • Once you find a match, output "Yes, that word is in the dictionary"....
CSE 231                                         &n
CSE 231                                                                                                                        Fall 2019 Project #2 ## Language Should be Python. Assignment Specifications The program will compute and display information for a company which rents vehicles to its customers. For a specified customer, the program will compute and display the amount of money charged for that customer’s vehicle rental. The program should start by asking the user if he wants to continue. The answer is ‘Y’ for yes or ‘N’ for no. You can check the value with Boolean expressions such...
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...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...