//Ryan Shahriyarpour   CS1A    Carl Argila CH5 HW  Q:1
//
/*****************************************************************************
 * 
 * Sum of Numbers
 * 
 *********************
 * 
 * The program asks the user for a positive integer value. The program uses
 * a loop to get the sum of all the integers from 1 up to the number entered.
 * For example, if the user enters 50, the loop will find the sum of 
 * 1, 2, 3, 4, to 50.
 * 
 * INPUT
 *  num : A positive integer entered by the user
 * 
 * OUTPUT    
 *  sum : The sum of all integers from 1 to num
 * 
 ****************************************************************************/
 
#include <iostream>
using namespace std;
 
int main()
{
	int num;
	int sum = 0;
	
	cout << "Enter a positive integer: ";
	cin >> num;
	
	// Input validation
	if (num < 1)
	{
		cout << "Error: Please enter a positive integer.\n";
		return 0;
	}
	
	// Calculate the sum
	for (int i = 1; i <= num; i++)
	{
		sum += i;
	}
	
	cout << "The sum of 1 through " << num << " is " << sum << endl;
	
	return 0;
}