//Cameron Pham             CS1A                       Chapter 5, p. 294, #1
//
/******************************************************************************
* CALCULATE SUM OF NUMBERS
* ______________________________________________________________________________
* This program accepts a positive integer value and performs a loop to compute 
* the sum of all integers from 1 up to the value accepted.
* ______________________________________________________________________________
* INPUT
* Integer // Positive integer value 
* 
* OUTPUT
* Sum // Sum of all the integers from 1 up to the number entered.
*******************************************************************************/
#include <iostream>
using namespace std;

int main() 
{
	//Initalize Variables
int integer; 
int sum; 

	//Ask the user to enter a value.
cout << "Please enter a value, and I will calculate the sum of all the";
cout << " integers from 1 up to the number you have entered.";
cin >> integer; 
cout << endl << "You have entered " << integer << "." << endl; 

	//Validate the input.
while (integer < 0)
	{
		cout << "Your input cannot be a negative number. Please try again! ";
		cin >> integer;
	}
	
	//Calculate the sum.
for (int count = 1; count <= integer; count++)
	{
		sum += count;
	}
	
	//Display the sum.
cout << "The sum of the integers from 1 to " << integer << " is " << sum << ".";

	return 0;
}