Question: Please submit your corrections to the debugging exercises in Chapters 6 and 7 Chapter 6 - page 264, 1. The programmer intends for this pseudocode

Please submit your corrections to the debugging exercises in Chapters 6 and 7

Chapter 6 - page 264,

1. The programmer intends for this pseudocode to display three random numbers in

the range of 1 through 7. According to the way weve been generating random

numbers in this book, however, there appears to be an error. Can you find it?

// This program displays three random numbers

// in the range of 1 through 7.

Declare Integer count

// Display three random numbers.

For count = 1 To 3

Display random(7, 1)

End For

2. Can you find the reason that the following pseudocode function does not return

the value indicated in the comments?

// The calcDiscountPrice function accepts an items price and

// the discount percentage as arguments. It uses those

// values to calculate and return the discounted price.

Function Real calcDiscountPrice(Real price, Real percentage)

// Calculate the discount.

Declare Real discount = price * percentage

// Subtract the discount from the price.

Declare Real discountPrice = price discount

// Return the discount price.

Return discount

End Function

3. 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

Chapter 7 - page 280.

1. Why does the following pseudocode not perform as indicated in the comments?

// This program asks the user to enter a value

// between 1 and 10 and validates the input.

Declare Integer value

// Get a value from the user.

Display "Enter a value between 1 and 10."

Input value

// Make sure the value is between 1 and 10.

While value < 1 AND value > 10

Display "ERROR: The value must be between 1 and 10."

Display "Enter a value between 1 and 10."

Input value

End While

2. Why does the following pseudocode not perform as indicated in the comments?

// This program gets a dollar amount from the user

// and validates the input.

Declare Real amount

// Get the amount from the user.

Display "Enter a dollar amount"

Input amount

// Make sure the amount is not less than zero. If it is,

// get a new amount from the user.

While amount < 0

Display "ERROR: The dollar amount cannot be less than 0."

Display "Enter a dollar amount."

End While

3. The following pseudocode works, but it performs a case-sensitive validation of the

users input. How could the algorithm be improved so the user does not have to

pay attention to capitalization when entering a name?

// This program asks the user to enter a string

// and validates the input.

Declare String choice

// Get the user's response.

Display "Cast your vote for Chess Team Captain."

Display "Would you like to nominate Lisa or Tim?"

Input choice

// Validate the input.

While choice != "Lisa" AND choice != "Tim"

Display "Please enter Lisa or Tim."

Display "Cast your vote for Chess Team Captain."

Display "Would you like to nominate Lisa or Tim?"

Input response

End While

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!