LAB 04A - TRIANGLE REPL

Concepts

To gain practice with while loops, we will use a while loop to validate user input, and continue asking for input until a valid input is given.

Creating a REPL (Read, Evaluate, Print, Loop) is a way that we can repeatedly ask for a user's input and provide immediate feedback. We're going to build a REPL for triangle measurement input (because triangles are so cool, we just can't stop talking about them).

Instructions

This will be a new project. Create one and call it Lab04A. (Your solution to this Lab will be submitted with Homework 04, a week from this Wednesday.)

Recall in Lab 03B that a user enters three triangle measurements. In Lab03B, we checked a triangle's feasibility and set isTriangle to false if the measurements entered did not form a triangle. Wouldn't it be more useful if we could force the user to input valid measurements; that is, if we asked for input again if what was entered is invalid?

In a REPL program, you want to continually do the following:

  1. Ask user to enter input
  2. Read user input
  3. If input is invalid, go to step 1
  4. Do something based on the user input

In this assignment, you will ask the user to enter three real value measurements for their triangle, and store them in some variables. Then, continue to ask the user for their measurements until they are valid (i.e., all measurements > 0 and measurements form a triangle). Here is pseudocode for your Lab04A program:

  1. Ask user to enter three sides for a triangle
  2. Read their input
  3. If any measurement is <0, go to step 1
  4. If the measurements do not form a triangle, go to step 1
  5. Print "Woohoo - input is valid" and exit program

When creating this sort of input loop, it's important that the user understands what's taking place. If the user has entered invalid input, notify them of it appropriately (e.g., input is <0). It's helpful to put yourself in the user's shoes, and ask questions such as "If I were using this program, how would I want it to work?"