Schedule‎ > ‎

Lab 08B: Range Fun - extra lab

Part 1: User Input functions

In this project you write a function to read user input within a specified range.

Specifications

  1. Start with a new sketch and save the sketch using the name rangefun.
  2. Write a function with the following signature:
    /**
      Get user input within the specified range.
    
      @param prompt The message displayed prompting the user for input.
      @param min The minimum acceptable value
      @param max The maximum acceptable value
      @return A number between min and max
    */
    double readInRange(String prompt, double min, double max)
    
    The function name must be either readInRange or read_in_range depending on your coding style. You may use any parameter names but must use the type specified.
  3. The function must:
    1. Display the prompt
    2. Block and wait for user input
    3. Check that the user input is between min and max values

      If the input is not within the specified range, the function must provide an error message, loop and ask the user for new input.

    4. Return the first user input that meets the range specified.
  4. Your program must operate like that shown in the Example Output shown below.
  5. In your README.txt show the operation of your program for the following examples and at least two original examples, with the program name "rangefun" as a heading.
    rangefun
    --------
    Enter a number between 2 and 3: 1.00
    Error: number must be >= 2.00
    
    Enter a number between 2 and 3: 4.00
    Error: number must be <= 3.00
    
    Enter a number between 2 and 3: 2.00
    You entered: 2.00
    
    Enter a number between 2 and 3: 3.00
    You entered: 3.00
    
  6. Submit your rangefun.ino file as part of this assignment.

Example Output

Keeping Numbers Within Range

Enter a number between 2 and 3: 1.00
Error: number must be >= 2.00

Enter a number between 2 and 3: 4.00
Error: number must be <= 3.00

Enter a number between 2 and 3: 2.00
You entered: 2.00

Enter a number between 2 and 3: 3.00
You entered: 3.00

Comments