CIS 150 Programming Project: Repetition

Objectives

  • Use repetition
  • Get user input
  • Perform basic input validation
  • Perform a calculation using a loop
  • Display results of a calculation

Program requirements

  1. Include documentation comments at the start of the file.
  2. Follow the course style guidelines including indentation, naming conventions, spaces instead of tabs, etc.
  3. Declare integer variables for a start value, an end value, and a sum.
  4. Use a while or do/while loop to prompt the user and get an integer value between 1 and 500. If the user enters a value out of bounds, then display an error message and reprompt the user. Continue until the user enters a value within the requested range.
  5. Use a while or do/while loop to prompt the user and get an integer value between the starting value + 1 and 1000. If the user enters a value out of bounds, then display an error message and reprompt the user. Continue until the user enters a value within the requested range. The prompt must display the starting value plus one as the minimum value to be entered.
  6. Use a for loop to calculate the sum of the integers from the start value through the end value.
  7. Display the sum in a message which includes the start and end values. See the example program run for the specific format.

Example run

Enter starting value for loop (1 - 500): -3 Invalid starting value. Enter starting value for loop (1 - 500): 501 Invalid starting value. Enter starting value for loop (1 - 500): 230 Enter ending value for loop (231 - 1000): 230 Invalid ending value. Enter ending value for loop (231 - 1000): 1001 Invalid ending value. Enter ending value for loop (231 - 1000): 782 The sum of the integers from 230 through 782 is 279818

Rubric

  • 2 points: Proper documentation comments
  • 3 points: Follows style guidelines used in class (indentation, no tabs, variable names start with a lowercase letter, etc.)
  • 2 points: Declare variables for start value, end value, and sum at start of program.
  • 8 points: Use a do/while or while loop to get a start value from the user within the range 1 through 500. The prompt must display the range. If the value the user enters is out of range, an error message must be displayed and the user re-prompted.
  • 10 points: Use a do/while or while loop to get an end value from the user within the range start+1 through 1000. The prompt must display the range. If the value the user enters is out of range, an error message must be displayed and the user re-prompted.
  • 3 points: Calculate the sum of the integers from the start value through the end value using a for loop.
  • 2 points: Display the result (sum) along with the start and end values. See the example run for the specific format.