// File: debugging.cpp
// Computes sum of integers from 1 to n
//
// Class: CS 210                     Instructor: Dr. Hwang / Dr. Roberts
// Assignment: Debugging Tutorial    Date : February 8 & 12, 2007
// Programmer(s): <fill in your name(s)>

#include <iostream>
using namespace std;

// Function prototypes
int Summation (int n);

int main ()
{

   // Local data
   int number,     // number to sum to
       result;     // sum from 1 to n
   char answer;    // user response


   cout << "This program computes the sum of the integers from 1 to\n"
        << "an integer entered by the user.\n\n";

   // Repeat until the user wants to quit
   do 
   {
      cout << "Please enter a non-negative number: ";
      cin >> number;
   
      result = Summation (number);
      cout << "The sum of the numbers from 1 to " << number 
           << " is " << result << endl;
      
      // Ask the user if want to continue
      cout << "Do another? (y/n) ";
      cin >> answer;
   } while ((answer != 'N') || (answer != 'n'));

   return 0;
} // end main


// Function: Summation
// Returns the sum of integers from 1 to n
int Summation (int n)   // RECEIVED: upper bound
{
   // Local data
   int sum,    // accumulates sum
       count;  // counter variable

   sum = 0;
   count = 1;

   // Compute 1 + 2 + ... + N
   while (count <= n)
   {
      sum = sum + n;
      count++;
   }  // end while
   return sum;
} // Summation
