0

I've been creating a program that determines the number of paint cans required to paint a room. My professor had us write the pseudocode for the program, and now wants us to modify the code by inputting different kinds of LOOPS, such as the WHILE, DO…WHILE, and FOR…NEXT.

I have to include two of the three different looping structures (while, do…while, for…next) somewhere within my project pseudocode.

This is what my current pseudocode looks like, but I don't know which two loops would work the best or how to input them into the already existing pseudocode.

Start

Display "Enter room length"

Input roomLength

Display "Enter room width"

Input roomWidth

Display "Enter room height"

Input roomHeight

Display "Enter number of doors"

Inputs doors

Display "Enter number of windows"

Input windows

Set paintCans = (L x W x H) - (20 sq. ft. per door & 15 sq. ft. per window) / (400 sq. ft. per gallon)

Display "Total cans of paint is", + paintCans

End
7
  • Are you sure you mean "pseudocode"? As in "code that won't be actually executed by a computer, so you're free to put in whatever, as long as it makes sense to a human reader?" Commented May 2, 2023 at 18:54
  • @SergioTulentsev, yes it's pseudocode. My professor has us write out the code for our program, simply typing it into a document before submission. Commented May 2, 2023 at 18:58
  • A loop will repeat some logic. Which logic do you want to repeat? Commented May 2, 2023 at 19:10
  • @trincot I know I could use a While Loop when determining the area of the room. Something like: While room < 0 Display “ERROR: The room cannot be less than 0.” Display “Enter the correct area.” Input area End While Commented May 2, 2023 at 21:11
  • Which is the second logic you want to repeat? Commented May 2, 2023 at 21:17

1 Answer 1

0

Inputs doors

// Use a WHILE loop to validate input for doors
**While** doors < 0
Display "Invalid input. Please enter a positive number of doors:"
Input doors
End While

Display "Enter number of windows"

Input windows

// Use a DO...WHILE loop to validate input for windows

**Do**
If windows < 0 Then
Display "Invalid input. Please enter a positive number of windows:"
Input windows
End If
Loop **While** windows < 0

Explanation:

In this modified pseudocode, a WHILE loop is used to ensure that the user inputs a positive number for the number of doors. If the user enters a negative number or zero, the loop will continue to prompt the user until a positive number is entered.

A DO...WHILE loop is used to ensure that the user inputs a positive number for the number of windows. The loop will prompt the user for input at least once, and will continue to do so until a positive number is entered.

After validating the inputs, the paintable square footage and the number of paint cans required are calculated as before, and the result is displayed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.