//Timothy Price			CS1A			CH5 Challenge 1
/*******************************************************************************
 * Calculate total
 * 
 * This program receives a number and calculates the total of all previous
 * numbers up to the selected number.
 * 
 * Inputs:
 * Positive number
 * 
 * Output:
 * Sum of numbers
 ******************************************************************************/
 
#include <iostream>

using namespace std;

int main() {
	
	// Data dictionary:
    int number;		// The number must be positive
    int sum = 0;

	// Program asks for a positive value, and gives choice feedback:
    cout << "Enter a positive integer value: " << endl;;
    cin >> number;
    cout << "You have entered the number " << number << "." << endl;

	// Rejection for invalid input:
    if (number <= 0) {
        cout << "Invalid input. Please enter a positive integer: " << endl;
    }
    // For valid input:
    if (number > 0) {		// Loop crated to calculate sum of all numbers:
		for (int base = 1; base <= number; ++base) {
			sum += base;
		}
		// Display sum:
		cout << "The sum of all numbers between 1 and " << number << " is ";
		cout << sum << "." << endl;
    }
    return 0;
}