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 and 5."
Input number
End While
The error is in the while loop,
When we want to make sure that the number is between 1 and 5, then we should use OR instead of AND, because, if we use AND, then code will not be executed because any of the condition can satisfy.
So, we should use OR instead of AND.
Correct psuedocode will be -->
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 OR number > 5
Display "ERROR: The number must be between 1 and 5. "
Display "Enter a number between 1 and 5."
Input number
End While
Get Answers For Free
Most questions answered within 1 hours.