CS 1500-2, Spring 2009
Lab 3 Extra Credit
Due Wednesday, April 1, 2009

More Practice with Loops

Write a program (either individually or with your partner) that sums the numbers from 1 to n, inclusive, where n is input by the user. For example, if I give you three, your program will compute 1+2+3 and output 6.

A good way to do this is to write a loop. The question is which loop to choose? Let's experiment with some of the options. Try it with 4 different loops:
Design you output to show the results of each loop separately.

Individual steps:

  1. Think through how you might sum n numbers. One way to solve this is with a loop. Write a program that takes a value n from the user and adds up the numbers from 1 to n inclusive. You program should use four different loops: for loop with increment, for loop with decrement, while loop with increment, while loop with decrement. Then print the output value of each loop to the screen.

  2. Make a script (you could call it lab03_ec.script) testing your program for at least n = 100 (more testing would be better, see section 3.4 of out book). Be sure to filter the script and directed at the bottom of the script page.

  3. Upload your source code (lab03_ec.cpp) and your script (lab03_ec.script) to the CSHomework system. Each student should upload a copy under their own name.


For the due dates, see the class schedule.